Lots of tidying up and making code consistent