Only create tmp if necessary
Refactor