fix multithreading issue