Fixed multithreading issue