Updated code, thank you @danpetruk from hashcode.ru