added global messages sending and correct exit handler