Tidied up code