Fixing concurrency issues with multiple threads.