Tidied up some of the functionality