cleaned up tempfile handling