Misc fixes

See commit comment for details