It was problem with allocating needed space, now it's okay. Anyway, the code of function is being attached..
-- Kamil Kukura