fixed some recursion bugs