Improve task-3 solution