tidy up and fix a minor bug