fixed bug of thread implementation