Fixed atexit routine