fix the tail recursion