Fixed recursion bugs