Move TreeFactory to its own file