recursion to iteration