implemented recursion based on tolerance, not number of iterations as it was before..