improved hessian loop generation