anchor.diff:  %%% Internal functions
   %%%===================================================================
   
  -maybe_handle(Response) when is_binary(Response) ->
  -    Decoded = jsx:decode(Response, [return_maps]),
  -    maybe_handle(Decoded);
  -maybe_handle(#{<<"sessionToken">> := Token}) ->
  -    {ok, Token};
  -maybe_handle(#{<<"loginStatus">> := Reason}) ->
  -    {error, Reason}.
  +%% TODO these look generic - maybe use elsewhere?
  +
  +receive_response(Self, Stream, Connection, Handler) ->
  +    receive
  +        {gun_response, Connection, Stream, fin, _Status, _Headers} ->
  +            no_data;
  +        {gun_response, Connection, Stream, nofin, _Status, _Headers} ->
  +            %% TODO only receive if 200 status?
  +            receive_data(Self, Connection, Stream, Handler);
  +        {'DOWN', _, process, Connection, Reason} ->
  +            error_logger:error_msg("Oops!"),
  +            exit(Reason)
  +    after 1000 ->
  +            exit(timeout)
  +    end.
  +
  +receive_data(Self, Connection, Stream, Handler) ->
  +    receive
  +        {gun_data, _Connection, _Stream, nofin, _Data} ->
  +            receive_data(Self, Connection, Stream, Handler);
  +        {gun_data, _Connection, Stream, fin, Data} ->
  +            lager:info("Received Data ~p", [Data]),
  +            Response = jsx:decode(Data, [return_maps, {labels, atom}]),
  +            Self ! Handler(Response);
  +        {'DOWN', _, process, _Connection, Reason} ->
  +            _ = lager:error("Oops!"),
  +            exit(Reason)
  +    after 1000 ->
  +            exit(timeout)
  +    end.
  +
  +
  +login_handler(#{sessionToken := Token, loginStatus := _Reason}) ->
  +    {token, Token};
  +login_handler(#{loginStatus := Reason}) ->
  +    exit(Reason).
  +
  +keep_alive_handler(#{token := Token, status := <<"SUCCESS">>}) ->
  +    {token, Token};
  +keep_alive_handler(#{status := <<"SUCCESS">>, error := Reason}) ->
  +    exit(Reason).
  +
  +
  +keep_alive(KeepAliveInterval) ->
  +    erlang:send_after(KeepAliveInterval, self(), keep_alive).
  
positive.code: 
  -export_type([token/0]).
  
  -record(state, {credentials::betfair:credentials(), connection, token}).
  
  %%%===================================================================
  %%% API
  
negative.code: -export([start_link/0]).
  -export([login/0]).
  -export([get_token/0]).
  -export([update_token/1]).
  
  
  %% gen_server callbacks
  