A few bug fixes

See commit comments