Tidied up the code a bit, divided it into more classes