Flagging branch

Features aren't fully complete here, but I've done so much refactoring that it's not going to be easy to make progress on other features until this patch lands. Not ideal, I know, I should be doing refactorings in topic branches, but the sooner this lands, the better. I'm essentially blocked until it does.