changed matrix assembly and fixed error in hessian calculation