Tidying up duplicate code