Fix termination detection