Tidying up repeated code