refactored first function