Minor bug fixes and tidying.