Convert recursive functions to iterative.