Fixed multithreading issues.