refactoring. detect infinite recursion