Code cleanup and restructuring. Some new functionality added in the Trees class.