Fix validate, refactoring code

Signed-off-by: Victor Zagnitko <victor.zagnitko@yandex.ru>