Tree tm

Review by @DarkDimius. I had independently done something very similar to #144, based on the commits in there. So it was easiest to just continue that way and push it. It's logically almost the same as #144, with the exception of the retypeSelect treatment.