Stocks close higher after gaining steam in final hour