Tidied up and added additional comments