builds the tree