Small amount of refactoring and general tidying up.