US stock market closes 2023 with best performance in years