A little tidying and refactoring