Tidied up and added test