Code repetition refactored