fix recursive->iterative conversion