Some tidy up and template support