made the gradient computation a bit faster