before removal of detailed debug prints
rearr
more stable grad/hessian support