Clean up tree generation wrapper functions
 - And also tidied up some of the data structures involved