Fixed the gradient bug