better tempfile handling