add mainFunc and refactorig

Signed-off-by: Alexandr Kriptononv <alexandr.kriptonov@gmail.com>