Improved unit tests for thread safetiness
Improved creation of tmp dirs.