Fix multithreading