Somewhat works

Gradient is still bugged, and it stops after one iteration.