Use atexit for the cleanup