US stocks close higher, mostly recovering from previous losses