Refactoring and recursion