minor bug-fixes and tidy-ups