minor tidying and small efficiencies