anchor.diff:  mask(<<>>, _) ->
       <<>>;
   mask(<<D:24>>, <<M:24, _:8>>) ->
  -   crypto:exor(<<D:24>>, <<M:24>>);
  +    crypto:exor(<<D:24>>, <<M:24>>);
   mask(<<D:16>>, <<M:16, _:16>>) ->
  -   crypto:exor(<<D:16>>, <<M:16>>);
  +    crypto:exor(<<D:16>>, <<M:16>>);
   mask(<<D>>, <<M, _:24>>) ->
  -   crypto:exor(<<D:8>>, <<M:8>>);
  +    crypto:exor(<<D:8>>, <<M:8>>);
   mask(<<D:32, Rest/bits >>, M) ->
  -   Data = crypto:exor(<<D:32>>, M),
  -   MaskedRest = mask(Rest, M),
  -   << Data:32/bits, MaskedRest/bits >>.
  +    Data = crypto:exor(<<D:32>>, M),
  +    MaskedRest = mask(Rest, M),
  +    << Data:32/bits, MaskedRest/bits >>.
   
   unmask(0, Data) ->
       Data;
   unmask(1, << Mask:32, Data/bits >> ) ->
       mask(Data, <<Mask:32>>).
   
  +op_to_atom(?OP_CONT) -> cont;
   op_to_atom(?OP_TEXT) -> text;
   op_to_atom(?OP_BINARY) -> binary;
   op_to_atom(?OP_PING) -> ping;
   op_to_atom(?OP_PONG) -> pong;
   op_to_atom(?OP_CLOSE) -> close.
   
  -complete_payload(Len, Size) when Len =< Size ->
  -    complete;
  -complete_payload(_,_) ->
  -    incomplete.
  -
  -unframe(Data) when byte_size(Data) < 2 ->
  -    {incomplete, 0,<<>>,0,Data};
  +contains_full_frame(Data) when byte_size(Data) < 2 ->
  +     false;
  +contains_full_frame(<< _:9, Data/bits >>) ->
  +    case decode_len(Data) of
  +	error -> 
  +	    false;
  +	{Len, Rest} -> 
  +	    byte_size(Rest) >= Len
  +    end.
  +  
  +recv_data(Sock, Buf) ->
  +    {Stat, B} = gen_tcp:recv(Sock, 0),
  +    case Stat of
  +         ok ->
  +            NewBuf = << Buf/binary, B/binary >>, 
  +	    case contains_full_frame(NewBuf) of
  +		true ->
  +		    unframe(NewBuf);
  +		_ ->
  +		    recv_data(Sock, NewBuf)
  +	    end; 
  +	error -> error
  +    end.
  +
   unframe(<< F:1, _:3, Op:4, M:1, Data/bits >>) ->
       {Len, Buf} = decode_len(Data),
  -    case complete_payload(Len,byte_size(Buf)) of 
  -         complete ->
  -             <<Payload:Len/bytes,Rest/bytes>> = Buf,
  -            {complete_payload(Len,byte_size(Payload)),op_to_atom(Op),unmask(M,Payload),F,Rest};
  -        incomplete ->
  -            {incomplete, 0,<<>>,0,Data}
  -    end.
  +    <<Payload:Len/bytes,RestBuf/bytes>> = Buf,
  +    {op_to_atom(Op),unmask(M,Payload),F,RestBuf}.
   
   frame(Op, Data) ->
       F = 1,
  
positive.code:                 host, port, path,
                  sock,
                  headers,
                  raw_buffer = <<>>,
                  buffer = <<>>,
                  op_cont,
                  recv_frames = []}).
  
  %%----------------------------------------------------------------------------
  %% API
  
negative.code: 
  encode_len(Len) when Len < 126 ->
      << Len:7 >>;
  encode_len(Len) when Len =< 16#ffff ->
      << 126:7, Len:16 >>;
  encode_len(Len) when Len =< 16#7fffffffffffffff ->
      << 127:7, Len:64 >>.
  
  decode_len(<<127:7, Len:64, Rest/bytes>>) ->
  