Tidied up and commented