Fix termination bug