anchor.diff:  handle_cast({connect, JID, IPAddress}, State) ->
     Doc = doc_create_connection(JID, IPAddress),
     mongo_do(State, copilot, fun () -> mongo:save(connections, Doc) end);
  -handle_cast({disconnect, {User, Host, Resource} = JID, IPAddress}, State) ->
  +handle_cast({disconnect, {User, Host, Resource} = JID, _IPAddress}, State) ->
     mongo_do(State, copilot, fun () ->
  -    Cursor = mongo:find(connections, {user, utf8(User),
  -                                      host, utf8(Host),
  -                                      resource, utf8(Resource),
  +    Cursor = mongo:find(connections, {user, bson:utf8(User),
  +                                      host, bson:utf8(Host),
  +                                      resource, bson:utf8(Resource),
                                         connected, true}),
       NewDoc = doc_close_connection(mongo:next(Cursor), JID, IPAddress),
       mongo:close_cursor(Cursor),
  
positive.code:   Lng = proplists:get_value(longitude, GeoData),
    Lat = proplists:get_value(latitude, GeoData),
  
    {user,         utf8(User),
     host,         utf8(Host),
     resource,     utf8(Resource),
     loc,          [Lng, Lat],
     connected_at, bson:timenow(),
     connected,    true}.
  
negative.code: 
    ok.
  
  on_set_presence(User, Server, Resource, _Packet) ->
    {IPAddress, _} = ejabberd_sm:get_user_ip(User, Server, Resource),
    handle_presence(connect, {User, Server, Resource}, IPAddress).
  on_unset_presence(User, Server, Resource, _Status) ->
    handle_presence(disconnect, {User, Server, Resource}, null).
  
  %@doc Handles presence stanzas sent by users
  handle_presence(UserState, JID, IPAddress) ->
    % Processes the stanza in the gen_server
    gen_server:cast(?MODULE, {UserState, JID, IPAddress}),
    report_event(Server, atom_to_list(UserState)),
    ok.
  