separated first function, created main function and replacd all exit() with raise Exception