replacing KeyboardInterrupt with atexit