Added safeguard against underflow.