add callback for application exit.