add atexit and on_exit