anchor.diff:              {ok, Req, undefined_state}
       end.
   
  +handle(Req, State) ->
  +    http_handle(Req, State).
  +
   websocket_init(_TransportName, Req, _Opts) ->
       {ok, Req, undefined_state}.
   
  -handle(Req, State) ->
  -    {Action, _} = cowboy_http_req:binding(action, Req),
  -    {Key, _} = cowboy_http_req:qs_val(<<"key">>, Req),
  - 
  -    RawReply = case Action of 
  -        <<"get">> ->
  -            {Range, _} = cowboy_http_req:qs_val(<<"range">>, Req),
  -            [Start, End] = binary:split(Range, <<",">> ), 
  -            yasa:get(Key, Start, End);
  -        <<"set">> ->
  -            {TS, _} = cowboy_http_req:qs_val(<<"timestamp">>, Req),
  -            {Value, _} = cowboy_http_req:qs_val(<<"value">>, Req),
  -            yasa:set(Key, Value, TS);
  -        <<"incr">> ->
  -            {TS, _} = cowboy_http_req:qs_val(<<"timestamp">>, Req),
  -            {Value, _} = cowboy_http_req:qs_val(<<"value">>, Req),
  -            yasa:incr(Key, Value, TS)
  -    end,
  -    Reply = process_raw_reply(RawReply),
  -    {ok, Req2} = cowboy_http_req:reply(200, [], Reply, Req),
  +%
  +% HTTP Handler
  +%
  +
  +http_handle(Req, State) ->
  +    ReplyHeader = [{'Content-Type', "application/json; charset=utf-8"}],
  +
  +    {Method, _} = cowboy_http_req:binding(action, Req),
  +    Key = pval(<<"key">>, Req),
  +    Callback = pval(<<"callback">>, Req), % json-p callback
  +
  +    {Status, RawReply} = reply(Key, Method, Req),
  +    Reply = jsonp(Callback, jsx:to_json(RawReply)),
  +
  +    {ok, Req2} = cowboy_http_req:reply(Status, ReplyHeader, Reply, Req),
       {ok, Req2, State}.
   
  +%
  +% Websocket Handler
  +%
  +
   websocket_handle({text, Json}, Req, State) ->
  -    Op = jsx:to_term(Json),
  -    Method = proplists:get_value(<<"method">>, Op), 
  -    Key = proplists:get_value(<<"key">>, Op), 
  -    RawReply = case Method of 
  -        <<"get">> ->
  -            Range = proplists:get_value(<<"range">>, Op),
  -            [Start, End] = binary:split(Range, <<",">> ), 
  -            yasa:get(Key, Start, End);
  -        <<"set">> ->
  -            TS = proplists:get_value(<<"timestamp">>, Op),
  -            Value = proplists:get_value(<<"value">>, Op),
  -            yasa:set(Key, Value, TS);
  -        <<"incr">> ->
  -            TS = proplists:get_value(<<"timestamp">>, Op),
  -            Value = proplists:get_value(<<"value">>, Op),
  -            yasa:incr(Key, Value, TS)
  -    end,
  -    Reply = process_raw_reply(RawReply),
  +    Proplist = jsx:to_term(Json),
  +    Method = proplists:get_value(<<"method">>, Proplist), 
  +    Key = pval(<<"key">>, Proplist), 
  +
  +    RawReply = reply(Key, Method, Proplist),
  +    Reply = jsx:to_json(RawReply),
  +
       {reply, {text, Reply}, Req, State};
  +
   websocket_handle(_Data, Req, State) ->
       {ok, Req, State}.
   
  
positive.code:     ok.
  terminate(_Req, _State) ->
      ok.
  %%%%%%%%%%%%%%%%%%%%
  % Internal Functions
  %%%%%%%%%%%%%%%%%%%%
  
  process_raw_reply(ok) -> <<"ok">>;
  process_raw_reply(Values) when is_list(Values) -> jsx:to_json(Values).
negative.code: %websocket callbacks
  -export([websocket_init/3, websocket_handle/3,
      websocket_info/3, websocket_terminate/3]).
  
  -define(l2b(X), list_to_binary(X)).
  
  init({tcp,http}, Req, _Opts) -> 
      {IsWebSocket,_} = cowboy_http_req:header('Upgrade',Req,false),
  