Some minor tidying and refactoring