Miscellaneous cleanup

Lots of misc cleanup here. Sorry if this PR is too kitchen-sinky! Let me know and I'll split it up.