Refactoring tmp to be more concurrent-friendly