Fixed a mistake in the gradient computation