fix bug in thread