Miscellaneous cleanups

Please see commit messages for details.