anchor.diff:      debug_fun(Msg, D),
       keep_state_and_data;
   
  -handle_event(internal, Msg=#ssh_msg_global_request{},            StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_request_success{},           StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_request_failure{},           StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_channel_open{},              StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_channel_open_confirmation{}, StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_channel_open_failure{},      StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_channel_window_adjust{},     StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_channel_data{},              StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_channel_extended_data{},     StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_channel_eof{},               StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_channel_close{},  {connected,server} = StateName, D) ->
  -    handle_connection_msg(Msg, StateName, cache_request_idle_timer_check(D));
  -
  -handle_event(internal, Msg=#ssh_msg_channel_close{},             StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_channel_request{},           StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_channel_success{},           StateName, D) ->
  -    update_inet_buffers(D#data.socket),
  -    handle_connection_msg(Msg, StateName, D);
  -
  -handle_event(internal, Msg=#ssh_msg_channel_failure{},           StateName, D) ->
  -    handle_connection_msg(Msg, StateName, D);
  -
  +handle_event(internal, {conn_msg,Msg}, StateName, #data{starter = User,
  +                                                        connection_state = Connection0,
  +                                                        event_queue = Qev0} = D0) ->
  +    Role = role(StateName),
  +    Rengotation = renegotiation(StateName),
  +    try ssh_connection:handle_msg(Msg, Connection0, Role) of
  +	{disconnect, Reason0, RepliesConn} ->
  +            {Repls, D} = send_replies(RepliesConn, D0),
  +            case {Reason0,Role} of
  +                {{_, Reason}, client} when ((StateName =/= {connected,client})
  +                                            and (not Rengotation)) ->
  +		   User ! {self(), not_connected, Reason};
  +                _ ->
  +                    ok
  +            end,
  +            {stop_and_reply, {shutdown,normal}, Repls, D};
  +
  +	{Replies, Connection} when is_list(Replies) ->
  +	    {Repls, D} = 
  +		case StateName of
  +		    {connected,_} ->
  +			send_replies(Replies, D0#data{connection_state=Connection});
  +		    _ ->
  +			{ConnReplies, NonConnReplies} = lists:splitwith(fun not_connected_filter/1, Replies),
  +			send_replies(NonConnReplies, D0#data{event_queue = Qev0 ++ ConnReplies})
  +		end,
  +            case Msg of
  +                #ssh_msg_channel_close{} when StateName == {connected,server} ->
  +                    {keep_state, cache_request_idle_timer_check(D), Repls};
  +                #ssh_msg_channel_success{} ->
  +                    update_inet_buffers(D#data.socket),
  +                    {keep_state, D, Repls};
  +                _ ->
  +                    {keep_state, D, Repls}
  +            end
  +
  +    catch
  +	Class:Error ->
  +            {Repls, D1} = send_replies(ssh_connection:handle_stop(Connection0), D0),
  +            {Shutdown, D} = ?send_disconnect(?SSH_DISCONNECT_BY_APPLICATION,
  +                                             io_lib:format("Internal error: ~p:~p",[Class,Error]),
  +                                             StateName, D1),
  +            {stop_and_reply, Shutdown, Repls, D}
  +    end;
   
   handle_event(cast, renegotiate, {connected,Role}, D) ->
       {KeyInitMsg, SshPacket, Ssh} = ssh_transport:key_exchange_init_msg(D#data.ssh_params),
  
positive.code: 		   #data{}
  		  ) -> gen_statem:event_handler_result(state_name()) .
  		   
  %% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  
  callback_mode() ->
  
negative.code: 	    {keep_state_and_data, [{next_event, internal, {info_line,Info}}]}
      end;
  
  
  handle_event(info, {Proto, Sock, NewData}, StateName, D0 = #data{socket = Sock,
  								 transport_protocol = Proto}) ->
      try ssh_transport:handle_packet_part(
  