Finished refactoring, ready to start writing the tree generation code