bugs in thread shutdown