US markets end higher, recovering from previous losses