improved tempfile handling for machine output