changed to use signal instead of atexit