anchor.diff:      case tls_record:get_tls_records(Data, Versions, Buf0, SslOpts) of
   	{Records, Buf1} ->
   	    CT1 = CT0 ++ Records,
  -	    next_record(State0#state{protocol_buffers =
  +	    next_record(StateName, State0#state{protocol_buffers =
   					 Buffers#protocol_buffers{tls_record_buffer = Buf1,
   								  tls_cipher_texts = CT1}});
   	#alert{} = Alert ->
  
positive.code:      State#state{protocol_buffers = Buffers#protocol_buffers{tls_cipher_texts = CipherTexts},
                   connection_states = ConnectionStates}}.
  
  
  next_event(StateName, Record, State) ->
      next_event(StateName, Record, State, []).
  %%
  next_event(StateName, no_record, State0, Actions) ->
      case next_record(State0) of
   	{no_record, State} ->
              {next_state, StateName, State, Actions};
   	{#ssl_tls{} = Record, State} ->
   	    {next_state, StateName, State, [{next_event, internal, {protocol_record, Record}} | Actions]};
  	#alert{} = Alert ->
              Version = State0#state.connection_env#connection_env.negotiated_version,
              ssl_connection:handle_own_alert(Alert, Version, StateName, State0)
      end;
  next_event(StateName, Record, State, Actions) ->
      case Record of
  	no_record ->
  	    {next_state, StateName, State, Actions};
  	#ssl_tls{} = Record ->
  	    {next_state, StateName, State, [{next_event, internal, {protocol_record, Record}} | Actions]};
  	#alert{} = Alert ->
              Version = State#state.connection_env#connection_env.negotiated_version,
              ssl_connection:handle_own_alert(Alert, Version, StateName, State)
      end.
  
  
  %%% TLS record protocol level application data messages 
  handle_protocol_record(#ssl_tls{type = ?APPLICATION_DATA, fragment = Data}, StateName, 
  
negative.code: %%====================================================================
  %% State transition handling
  %%====================================================================
  next_record(_, #state{handshake_env = 
                         #handshake_env{unprocessed_handshake_events = N} = HsEnv} 
              = State) when N > 0 ->
      {no_record, State#state{handshake_env = 
                                  HsEnv#handshake_env{unprocessed_handshake_events = N-1}}};
  next_record(_, #state{protocol_buffers =
                            #protocol_buffers{tls_cipher_texts = [_|_] = CipherTexts},
                        connection_states = ConnectionStates,
                        ssl_options = #ssl_options{padding_check = Check}} = State) ->
      next_record(State, CipherTexts, ConnectionStates, Check);
  next_record(connection, #state{protocol_buffers = #protocol_buffers{tls_cipher_texts = []},
                                 protocol_specific = #{active_n_toggle := true}
                                } = State) ->
      %% If ssl application user is not reading data wait to activate socket
      flow_ctrl(State); 
    
  next_record(_, #state{protocol_buffers = #protocol_buffers{tls_cipher_texts = []},
                        protocol_specific = #{active_n_toggle := true}
                       } = State) ->
      activate_socket(State);
  next_record(_, State) ->
      {no_record, State}.
  
  
  flow_ctrl(#state{user_data_buffer = {_,Size,_},
                   socket_options = #socket_options{active = false},
                   bytes_to_read = undefined} = State)  when Size =/= 0 ->
      {no_record, State};
  flow_ctrl(#state{user_data_buffer = {_,Size,_},
                   socket_options = #socket_options{active = false},
                   bytes_to_read = 0} = State)  when Size =/= 0 ->
      {no_record, State};
  flow_ctrl(#state{user_data_buffer = {_,Size,_}, 
                   socket_options = #socket_options{active = false},
                   bytes_to_read = BytesToRead} = State) when (Size >= BytesToRead) andalso
                                                              (BytesToRead > 0) ->
      {no_record, State};
  flow_ctrl(State) ->
      activate_socket(State).
  
  
  activate_socket(#state{protocol_specific = #{active_n_toggle := true, active_n := N} = ProtocolSpec,
                         static_env = #static_env{socket = Socket,
                                                  close_tag = CloseTag,
                                                  transport_cb = Transport}  
                        } = State) ->                                                                                                            
      case tls_socket:setopts(Transport, Socket, [{active, N}]) of
          ok ->
              {no_record, State#state{protocol_specific = ProtocolSpec#{active_n_toggle => false}}}; 
          _ ->
              self() ! {CloseTag, Socket},
              {no_record, State}
      end.
  
  %% Decipher next record and concatenate consecutive ?APPLICATION_DATA records into one
  %%
  