Minor bug-fixes and clean-up