Refactor tmp generation.