refactor to avoid infinite recursion