recursive refactor