made temporary file generation more robust