Tidied up so it can actually compile