changed convergence criterion and fixed a bug