minor tidyup, few null checks