Add improved solution for task 4