cleaning up the tree handling a bit more

this is a follow-up of #173 and contains the change from #173 because we touch the same places.