Clean up the tree code
This is preliminary cleanup toward being able to remove our own tree implementation and use the rctree crate.
There is still quite a bit of work to do to get there (if we want to), but these cleanups are probably worth anyway.