Fixes to bugs detected by Rob