Some refactoring to make it easier to retrieve trees.