Fix tests and some minor tidying