Added recursion refactoring