fix bug in multithreading