Updated termination condition for gradient descent