Minor bug fixes and format tidying.