Refactoring of Tree implementation