add tail recursion implementation.