Made task6 in another way. Works not fully correct.