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.

EDIT: This PR has been up so long, the features actually *are* fully complete. Waiting on @wolftune to do some cosmetic work, though.