tail recursion fix