Clean up treegen code

Created before #308, but I never got around to merging it apparently.
Both pulls include changes worthy of merging.
Done, for leaves of the same kind of tree.  Note that this is different behavior than there was previously though.