fixed bug in thread