Bug fixes introduced by sloppy coding (reported by Bart Kroon)