Tidy up and fix minor problems