anchor.diff:      RowId = proplists:get_value(<<"rowid">>, BodyJson, <<>>),
       CellId = proplists:get_value(<<"cellid">>, BodyJson, <<>>),
       Value = binary_to_list(proplists:get_value(<<"value">>, BodyJson, <<>>)),
  -    GuiResp = Statement:gui_req(update, [{RowId,upd,[{CellId,Value}]}]),
  -    GuiRespJson = gen_adapter:gui_resp(GuiResp, Statement:get_columns()),
  -    ?Info("updated ~p", [GuiResp]),
  -    From ! {reply, jsx:encode([{<<"update_data">>, GuiRespJson}])},
  +    Statement:gui_req(update, [{RowId,upd,[{CellId,Value}]}], gui_resp_cb_fun(<<"update_data">>, Statement, From)),
       Priv;
   process_cmd({[<<"delete_row">>], ReqBody}, From, Priv) ->
       [{<<"delete_row">>,BodyJson}] = ReqBody,
       Statement = binary_to_term(base64:decode(proplists:get_value(<<"statement">>, BodyJson, <<>>))),
       RowId = proplists:get_value(<<"rowid">>, BodyJson, <<>>),
  -    GuiResp = Statement:gui_req(update, [{RowId,del,[]}]),
  -    GuiRespJson = gen_adapter:gui_resp(GuiResp, Statement:get_columns()),
  -    ?Info("deleted ~p", [GuiResp]),
  -    From ! {reply, jsx:encode([{<<"delete_row">>, GuiRespJson}])},
  +    Statement:gui_req(update, [{RowId,del,[]}], gui_resp_cb_fun(<<"delete_row">>, Statement, From)),
       Priv;
   process_cmd({[<<"insert_data">>], ReqBody}, From, Priv) ->
       [{<<"insert_data">>,BodyJson}] = ReqBody,
       Statement = binary_to_term(base64:decode(proplists:get_value(<<"statement">>, BodyJson, <<>>))),
       ClmName = binary_to_list(proplists:get_value(<<"col">>, BodyJson, <<>>)),
       Value =  binary_to_list(proplists:get_value(<<"value">>, BodyJson, <<>>)),
  -    GuiResp = Statement:gui_req(update, [{undefined,ins,[{ClmName,Value}]}]),
  -    GuiRespJson = gen_adapter:gui_resp(GuiResp, Statement:get_columns()),
  -    ?Info("inserted ~p", [GuiResp]),
  -    From ! {reply, jsx:encode([{<<"insert_data">>, GuiRespJson}])},
  +    Statement:gui_req(update, [{undefined,ins,[{ClmName,Value}]}], gui_resp_cb_fun(<<"insert_data">>, Statement, From)),
       Priv;
   
   % unsupported gui actions
  
positive.code:     [{<<"button">>,BodyJson}] = ReqBody,
      Statement = binary_to_term(base64:decode(proplists:get_value(<<"statement">>, BodyJson, <<>>))),
      Button = proplists:get_value(<<"btn">>, BodyJson, <<">">>),
      GuiResp = Statement:gui_req(button, Button),
      GuiRespJson = gen_adapter:gui_resp(GuiResp, Statement:get_columns()),
      ?Debug("GUI response ~p", [GuiRespJson]),
      From ! {reply, jsx:encode([{<<"button">>, GuiRespJson}])},
      Priv;
  process_cmd({[<<"update_data">>], ReqBody}, From, Priv) ->
      [{<<"update_data">>,BodyJson}] = ReqBody,
  
negative.code:     Priv.
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%
  gui_resp_cb_fun(Cmd, Statement, From) ->
      fun(#gres{} = GuiResp) ->
          GuiRespJson = gen_adapter:gui_resp(GuiResp, Statement:get_columns()),
          ?Debug("resp ~p ~p", [Cmd, GuiResp]),
          From ! {reply, jsx:encode([{Cmd,GuiRespJson}])}
      end.
  
  sort_json_to_term([]) -> [];
  sort_json_to_term([[{C,T}|_]|Sorts]) ->
  