Tail recursion optimization.