anchor.diff:  handle_alerts([Alert | Alerts], {next_state, StateName, State}) ->
       handle_alerts(Alerts, handle_alert(Alert, StateName, State)).
   
  -handle_alert(#alert{level = ?FATAL} = Alert, connection, 
  -	     #state{from = From, user_application = {_Mon, Pid}, 
  -		    log_alert = Log,
  -		    host = Host, port = Port, session = Session,
  -		    role = Role, socket_options = Opts} = State) ->
  -    invalidate_session(Role, Host, Port, Session),
  -    log_alert(Log, connection, Alert),
  -    alert_user(Opts#socket_options.active, Pid, From, Alert, Role),
  -    {stop, normal, State};
  -
  -handle_alert(#alert{level = ?WARNING, description = ?CLOSE_NOTIFY} = Alert, 
  -	     connection, #state{from = From,
  -				role = Role,
  -				user_application = {_Mon, Pid}, 
  -				socket_options = Opts} = State) ->
  -    alert_user(Opts#socket_options.active, Pid, From, Alert, Role),
  -    {stop, normal, State};
  -
   handle_alert(#alert{level = ?FATAL} = Alert, StateName,
   	     #state{from = From, host = Host, port = Port, session = Session,
  -		    log_alert = Log, role = Role} = State) ->
  +		    user_application = {_Mon, Pid},
  +		    log_alert = Log, role = Role, socket_options = Opts} = State) ->
       invalidate_session(Role, Host, Port, Session),
       log_alert(Log, StateName, Alert),
  -    alert_user(From, Alert, Role),
  +    alert_user(StateName, Opts, Pid, From, Alert, Role),
       {stop, normal, State};
  +
   handle_alert(#alert{level = ?WARNING, description = ?CLOSE_NOTIFY} = Alert, 
  -	     _, #state{from = From, role = Role} = State) -> 
  -    alert_user(From, Alert, Role),
  +	     StateName, #state{from = From, role = Role,  
  +			       user_application = {_Mon, Pid}, socket_options = Opts} = State) -> 
  +    alert_user(StateName, Opts, Pid, From, Alert, Role),
       {stop, normal, State};
   
   handle_alert(#alert{level = ?WARNING, description = ?NO_RENEGOTIATION} = Alert, StateName, 
  
positive.code:     {Record, State} = next_record(State0),
      next_state(hello, Record, State);
  
  abbreviated(Finished = #finished{verify_data = Data},
  	    #state{role = server,
  		   negotiated_version = Version,
  		   tls_handshake_hashes = Hashes,
  
negative.code: handle_sync_event(close, _, _StateName, State) ->
      {stop, normal, ok, State};
  
  handle_sync_event({shutdown, How0}, _, StateName,
  		  #state{transport_cb = Transport,
  			 negotiated_version = Version,
  			 connection_states = ConnectionStates,
  			 socket = Socket} = State) ->
      case How0 of
  	How when How == write; How == both ->	    
  	    Alert = ?ALERT_REC(?WARNING, ?CLOSE_NOTIFY),
  	    {BinMsg, _} =
  		encode_alert(Alert, Version, ConnectionStates),
  	    Transport:send(Socket, BinMsg);
  	_ ->
  	    ok
      end,
      
      case Transport:shutdown(Socket, How0) of
  	ok ->
  	    {reply, ok, StateName, State};
  	Error ->
  