S&P 500 closes at record as US indexes bounce back from losses