fixed thread termination bug