-changed the termination condition of the newton-raphson procedure to avoid
 numerical issues with convergence in some cases
-this needs to be re-visited to use a more elaborate optimization procedure