Fixed a multithreading issue