refactored repeated code