fix the termination detection bug