restructure the tree