maxopt_*_gradient now cleaner code.

No real documentation yet.