Implement tail recursion. It does not make code run faster, but can avoid stack overflow problem.