mainly code tidy up