add some code for tail recursion