tidied up and simplified