Tidied up the code