Fixes tail recursion errors