US stocks close higher, S&P 500 near record high