refactoring to enable recursive behavior