Fixed multithreading issues