added convergence
made it a function