tree refactoring