Improve solution for task 5