partially debugged gradient and hessian