Changed recursion to while loop.