hess and jacobian of lagrangian placed in seperate function