Tesla, megacaps drive S&P500, Nasdaq to higher close