Tree builder

@sbleon, take a look at my first pass of the tree builder. Let's discuss additional refactoring when you have a few minutes.