fix multi-thread code