Multithreading fixes