Stocks notch gains, taking back some losses from previous day