builds a tree