Fix creating temp files.
Add env command + improve robustness