anchor.diff:  -module(mod_copilot).
   -behavior(gen_mod).
  --define(PROCNAME, mod_copilot).
  +-behaviour(gen_server).
  +
   -define(JID, "mod_copilot@localhost").
   
   -include("ejabberd.hrl").
   -include("jlib.hrl").
  --export([start/2, stop/1, on_presence/4, lookup_ip/1, ucfirst/1, report_event/2, report_event/4]).
   
  -start(Host, _Opt) ->
  +% Required by gen_mod
  +-export([start/2, stop/1, on_presence/4]).
  +% Required by gen_server
  +-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/2]).
  +% Utilites
  +-export([lookup_ip/1, ucfirst/1, report_event/2, report_event/4]).
  +
  +%%% ejabberd hooks %%%
  +start(Host, Opts) ->
     ?INFO_MSG("** init copilot plugin", []),
   
  -  application:start(mongodb),
  -  application:start(egeoip),
  +  % Starts the local gen_server under supervision of ejabberd
  +  Proc = gen_mod:get_module_proc(Host, ?MODULE),
  +  ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]},
  +                     permanent,
  +                     1000,
  +                     worker,
  +                     [?MODULE]},
  +  supervisor:start_child(ejabberd_sup, ChildSpec),
   
     ejabberd_hooks:add(set_presence_hook, Host, ?MODULE, on_presence, 50),
     ok.
  
positive.code: 
    ejabberd_hooks:delete(set_presence_hook, Host, ?MODULE, on_presence),
  
    application:stop(mongodb),
    application:stop(),
  
    ok.
  
  on_presence(User, Server, Resource, _Packet) ->
    {IPAddress, _} = ejabberd_sm:get_user_ip(User, Server, Resource),
    Data = lookup_ip(IPAddress),
    ?DEBUG("User with the IP address ~p sent a presence from (~p, ~p)", [IPAddress,
                                                                         lists:keyfind(latitude, 1, Data),
                                                                         lists:keyfind(longitude, 1, Data)]),
    report_event(Server, "connect"),
    ok.
  
  %%% Utilities %%%
  % Converts first character to uppercase
  
negative.code: 
  % Sends an message as mod_copilot@localhost and
  % performs base64-encoding of the attributes
  route_to_copilot_component(To, Xml) -> route_to_copilot_component(?JID, To, Xml).
  route_to_copilot_component(From, To, Xml) -> ejabberd_router:route(jlib:string_to_jid(From), jlib:string_to_jid(To), hash_xml_body(Xml)).
  
  hash_xml_body({xmlelement, Tag, Attributes, ChildNodes}) ->
    {xmlelement,
  