S&P 500 ends slightly higher as Tesla rallies