Saner and simplier juggling of tempfiles, added cleanup hook