Changed recursion to loop.