finally fixed multithreading bug