anchor.diff:          true -> Expires;
           false -> ?DEFAULT_EVENT_EXPIRES
       end,
  -    case Status of
  -        neutral ->
  -            cancel_timer(TimerN),
  -            cancel_timer(TimerExpire),
  -            cancel_timer(TimerMiddle),
  -            #call{opts=#call_opts{timer_t1=T1}} = Call,
  -            Subs1 = Subs#subscription{
  -                status = neutral,
  -                expires = Expires1,
  -                timer_n = start_timer(64*T1, {timeout, Id}, Dialog),
  -                timer_expire = start_timer(1000*Expires1, {timeout, Id}, Dialog),
  -                timer_middle = start_timer(500*Expires1, {middle, Id}, Dialog)
  -            },
  -            store(Subs1, Dialog, Call);
  -        _ ->
  -            cancel_timer(TimerN),
  -            cancel_timer(TimerExpire),
  -            cancel_timer(TimerMiddle),
  -            ?call_debug("Event ~s expired updated to ~p", [Id, Expires1], Call),
  -            Answered1 = case Answered of
  -                undefined -> nksip_lib:timestamp();
  -                _ -> Answered
  -            end,
  -            Subs1 = Subs#subscription{
  -                status = Status,
  -                answered = Answered1,
  -                timer_n = undefined,
  -                timer_expire = start_timer(1000*Expires1, {timeout, Id}, Dialog),
  -                timer_middle = start_timer(500*Expires1, {middle, Id}, Dialog)
  -            },
  -            store(Subs1, Dialog, Call)
  -    end;
  +    cancel_timer(TimerN),
  +    cancel_timer(TimerExpire),
  +    cancel_timer(TimerMiddle),
  +    ?call_debug("Event ~s expires updated to ~p", [Id, Expires1], Call),
  +    Answered1 = case Answered of
  +        undefined -> nksip_lib:timestamp();
  +        _ -> Answered
  +    end,
  +    Subs1 = Subs#subscription{
  +        status = Status,
  +        answered = Answered1,
  +        timer_n = undefined,
  +        timer_expire = start_timer(1000*Expires1, {timeout, Id}, Dialog),
  +        timer_middle = start_timer(500*Expires1, {middle, Id}, Dialog)
  +    },
  +    store(Subs1, Dialog, Call);
  +
  +update({terminated, Reason}, Subs, Dialog, Call) ->
  +    #subscription{
  +        id = Id,
  +        status = OldStatus,
  +        timer_n = N, 
  +        timer_expire = Expire, 
  +        timer_middle = Middle
  +    } = Subs,
  +    cancel_timer(N),
  +    cancel_timer(Expire),
  +    cancel_timer(Middle),
  +    ?call_debug("Subscription ~s ~p -> {terminated, ~p}", [Id, OldStatus, Reason], Call),
  +    cast({terminated, Reason}, Subs, Dialog, Call),
  +    store(Subs#subscription{status={terminated, Reason}}, Dialog, Call);
  +
  +
  +
   
   update(Status, Subs, Dialog, Call) ->
       update({terminated, Status}, Subs, Dialog, Call).
  
positive.code: 
  uas_do_response('SUBSCRIBE', Code, Req, Resp, Subs, Dialog, Call) 
                  when Code>=200, Code<300 ->
      case Subs#subscription.status of
          notify_wait -> 
              Expires = case min(Req#sipmsg.expires, Resp#sipmsg.expires) of
                  Expires0 when is_integer(Expires0), Expires0>=0 -> Expires0;
                  _ -> ?DEFAULT_EVENT_EXPIRES
              end,
              update({neutral, Expires}, Subs, Dialog, Call);
          _ -> 
              update(none, Subs, Dialog, Call)
      end;
          
  uas_do_response('SUBSCRIBE', Code, _Req, _Resp, Subs, Dialog, Call) 
                  when Code>=300 ->
  
negative.code:         id = Id,
          app_id = AppId,
          event = Event,
          status = start,
          class = Class,
          answered = undefined,
          timer_n = start_timer(64*T1, {tixmeout, Id}, Dialog)
  