Move gradient/step to own function