Fix atexit bad references
calling "exit" calls also the atexit functions!
FIXING issue #297
Added useful debug message
Merge pull request #320 from LocutusOfBorg/fix-atexit

Fix atexit bad references