Refactored repeated code