cleanup code to avoid its duplication

Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>