Refactor to reduce repetition