Solution of the problem. Working script.