A bit of refactoring to reduce repetition.