Refactor tree structure.