make and delete tmpfile, clean up modes before quitting