Fix tail recursion crash