Refactor for complete recursion