Refactored + clean up for building tree