Added comments and tidied up