Tidied up solution to 8