Refactoring to avoid repetition