Tidy up and added comments