task 4: refactored