Debugging logic, still hitting recursion limit