Fix threading issue
Unittests updated