Refactored task4