Refactored repeated code.