Stocks give up an early gain and close lower on Wall Street