Added comments and further tidying up