Collection of bug fixes and tidy ups