Fixing multithreading bugs.