add an exit event hook