Refactor && some test

Signed-off-by: Aleksey Snisar <osni@isd.dp.ua>