clean up tempfile code a bit