Recursive functions converted to tail recursion.