Fix errors in the gradient definition