anchor.diff:  handle_frames(FirstPacket, #state{wsstate=WSState,
                                     opts=Opts,
                                     unused_stream=Unused}=State) ->
  -    FrameInfos = case Unused of
  -        <<>> -> unframe(WSState, FirstPacket, Opts);
  -        _    -> unframe(WSState, <<Unused/binary, FirstPacket/binary>>, Opts)
  +    Stream = case Unused of
  +        <<>> -> FirstPacket;
  +        _    -> <<Unused/binary, FirstPacket/binary>>
       end,
  +    {FrameInfos, Remainder} = unframe(WSState, Stream, Opts),
  +    State0 = State#state{unused_stream = Remainder},
       Result = case State#state.cbtype of
  -                 basic    -> basic_messages(FrameInfos, State);
  -                 advanced -> advanced_messages(FrameInfos, State)
  +                 basic    -> basic_messages(FrameInfos, State0);
  +                 advanced -> advanced_messages(FrameInfos, State0)
                end,
       case Result of
           {ok, State1, Timeout} ->
  -            LastWsState = last_ws_state(FrameInfos, State1#state.wsstate),
  +            LastWsState = case FrameInfos of
  +                [] -> WSState;
  +                _  -> (lists:last(FrameInfos))#ws_frame_info.ws_state
  +            end,
               {noreply, State1#state{wsstate=LastWsState, wait_pong_frame=false},
                Timeout};
           {stop, State1} ->
  
positive.code:     basic_messages(FrameInfos, State, State#state.timeout).
  
  basic_messages([], State, Tout) ->
      {ok, State#state{unused_stream = <<>>}, Tout};
  basic_messages([{frame_incomplete, Unused}], State, Tout) ->
      %% Unused is a part of a potentially large (some kb) binary,
      %% so we copy it to detach it for gc purposes
      {ok, State#state{unused_stream = binary:copy(Unused, 1)}, Tout};
  basic_messages([FrameInfo|Rest],
                 #state{cbinfo=CbInfo, cbstate={FrameState,CbState}}=State,
                 Tout) ->
  
negative.code:     advanced_messages(FrameInfos, State, State#state.timeout).
  
  advanced_messages([], State, Tout) ->
      {ok, State, Tout};
  advanced_messages([FrameInfo|Rest], #state{close_timer=TRef}=State,
                    Tout) when TRef /= undefined ->
      case FrameInfo of
  