Converting Recursion to Iteration