tidied up some code