Wip 6585

This still needs testing (lots of testing), and some squashing of the commits, but I'm sending in the pull now so we don't lose comment history.