tidy'd up some code