improved tmpdir handling