Various fixes and tidy up