Misc fixes

See commit messages for details