Changed convergence criterion. See extensive comment in function.