refactored code 2