Miscellanneous fixes

See the commit messages for details.