rewrite logic

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