Tidied the code a bit