tidied up the code