tidy up some of the code