Tidy up a little and add comments