Upd main function