Tidied up - added comments to code