The US stock market had been on track for a much worse loss at the start of trading.