Fixed grad_iterate function