a bit of tidying up of subroutines