refactored function; prevent duplication