hacked in tail recursion