added some comments and a little tidy up