tidied up the code and added extensive comments