Fixed bugs in multi-thread work