Fix broken thread stop handling