Tidied up some code