tidyed up some code