Tidied the code slightly