Fixing multithreaded synchroniztion issues