Clean up hessian.m

Fix description of algorithm and document the function better. Also removes manual increasing of loop variable and moves computation of temporary variable not depending on loop variables outside of the loop as it needs to be computed only once.
Closes #763