anchor.diff:  %% API
   %%====================================================================
   %%--------------------------------------------------------------------
  -%% Function: start_link() -> ok,Pid} | ignore | {error,Error}
  -%% Description:Creates a gen_fsm process which calls Module:init/1 to
  -%% initialize. To ensure a synchronized start-up procedure, this function
  -%% does not return until Module:init/1 has returned.
  +%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
  +%% Description: Starts the server
   %%--------------------------------------------------------------------
   start_link(ControlPid, StatePid, Url, InfoHash, PeerId) ->
  -    gen_fsm:start_link(?MODULE,
  -		       [{ControlPid, StatePid, Url, InfoHash, PeerId}],
  -		       []).
  +    gen_server:start_link(?MODULE,
  +			  [{ControlPid, StatePid, Url, InfoHash, PeerId}],
  +			  []).
   
   contact_tracker_now(Pid) ->
  -    gen_fsm:send_event(Pid, contact_tracker_now).
  +    gen_server:cast(Pid, contact_tracker_now).
   
   start_now(Pid) ->
  -    gen_fsm:send_event(Pid, start_now).
  +    gen_server:cast(Pid, start_now).
   
   stop_now(Pid) ->
  -    gen_fsm:send_event(Pid, stop_now).
  +    gen_server:cast(Pid, stop_now).
   
   torrent_completed(Pid) ->
  -    gen_fsm:send_event(Pid, torrent_completed).
  -
  -%%====================================================================
  -%% gen_fsm callbacks
  -%%====================================================================
  -%%--------------------------------------------------------------------
  -%% Function: init(Args) -> {ok, StateName, State} |
  -%%                         {ok, StateName, State, Timeout} |
  -%%                         ignore                              |
  -%%                         {stop, StopReason}
  -%% Description:Whenever a gen_fsm is started using gen_fsm:start/[3,4] or
  -%% gen_fsm:start_link/3,4, this function is called by the new process to
  -%% initialize.
  +    gen_server:cast(Pid, torrent_completed).
  +
  +%%====================================================================
  +%% gen_server callbacks
  +%%====================================================================
  +
  +%%--------------------------------------------------------------------
  +%% Function: init(Args) -> {ok, State} |
  +%%                         {ok, State, Timeout} |
  +%%                         ignore               |
  +%%                         {stop, Reason}
  +%% Description: Initiates the server
   %%--------------------------------------------------------------------
   init([{ControlPid, StatePid, Url, InfoHash, PeerId}]) ->
  -    {ok, tracker_wait, #state{should_contact_tracker = false,
  -			      control_pid = ControlPid,
  -			      state_pid = StatePid,
  -			      url = Url,
  -			      info_hash = InfoHash,
  -			      peer_id = PeerId}}.
  -
  -%%--------------------------------------------------------------------
  -%% Function:
  -%% state_name(Event, State) -> {next_state, NextStateName, NextState}|
  -%%                             {next_state, NextStateName,
  -%%                                NextState, Timeout} |
  -%%                             {stop, Reason, NewState}
  -%% Description:There should be one instance of this function for each possible
  -%% state name. Whenever a gen_fsm receives an event sent using
  -%% gen_fsm:send_event/2, the instance of this function with the same name as
  -%% the current state name StateName is called to handle the event. It is also
  -%% called if a timeout occurs.
  -%%--------------------------------------------------------------------
  -tracker_wait(start_now, S) ->
  -    {next_state, tracker_wait, handle_nonregular(S, "started")};
  -tracker_wait(stop_now, S) ->
  -    {next_state, tracker_wait, handle_nonregular(S, "stopped")};
  -tracker_wait(torrent_completed, S) ->
  -    {next_state, tracker_wait, handle_nonregular(S, "completed")};
  -tracker_wait({timeout, R, reinstall_timer}, S) ->
  -    R = S#state.timer,
  -    NS = install_timer(S#state.time_left, S),
  -    {next_state, tracker_wait, NS};
  -tracker_wait({timeout, R, may_contact}, S) ->
  -    R = S#state.timer,
  -    {next_state, tracker_wait, handle_tracker_contact(S, none)}.
  -
  -%%--------------------------------------------------------------------
  -%% Function:
  -%% state_name(Event, From, State) -> {next_state, NextStateName, NextState} |
  -%%                                   {next_state, NextStateName,
  -%%                                     NextState, Timeout} |
  -%%                                   {reply, Reply, NextStateName, NextState}|
  -%%                                   {reply, Reply, NextStateName,
  -%%                                    NextState, Timeout} |
  -%%                                   {stop, Reason, NewState}|
  -%%                                   {stop, Reason, Reply, NewState}
  -%% Description: There should be one instance of this function for each
  -%% possible state name. Whenever a gen_fsm receives an event sent using
  -%% gen_fsm:sync_send_event/2,3, the instance of this function with the same
  -%% name as the current state name StateName is called to handle the event.
  -%%--------------------------------------------------------------------
  -state_name(_Event, _From, State) ->
  +    {ok, #state{should_contact_tracker = false,
  +		control_pid = ControlPid,
  +		state_pid = StatePid,
  +		url = Url,
  +		info_hash = InfoHash,
  +		peer_id = PeerId}}.
  +
  +%%--------------------------------------------------------------------
  +%% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} |
  +%%                                      {reply, Reply, State, Timeout} |
  +%%                                      {noreply, State} |
  +%%                                      {noreply, State, Timeout} |
  +%%                                      {stop, Reason, Reply, State} |
  +%%                                      {stop, Reason, State}
  +%% Description: Handling call messages
  +%%--------------------------------------------------------------------
  +handle_call(_Request, _From, State) ->
       Reply = ok,
  -    {reply, Reply, state_name, State}.
  -
  -%%--------------------------------------------------------------------
  -%% Function:
  -%% handle_event(Event, StateName, State) -> {next_state, NextStateName,
  -%%						  NextState} |
  -%%                                          {next_state, NextStateName,
  -%%					          NextState, Timeout} |
  -%%                                          {stop, Reason, NewState}
  -%% Description: Whenever a gen_fsm receives an event sent using
  -%% gen_fsm:send_all_state_event/2, this function is called to handle
  -%% the event.
  -%%--------------------------------------------------------------------
  -handle_event(_Event, StateName, State) ->
  -    {next_state, StateName, State}.
  -
  -%%--------------------------------------------------------------------
  -%% Function:
  -%% handle_sync_event(Event, From, StateName,
  -%%                   State) -> {next_state, NextStateName, NextState} |
  -%%                             {next_state, NextStateName, NextState,
  -%%                              Timeout} |
  -%%                             {reply, Reply, NextStateName, NextState}|
  -%%                             {reply, Reply, NextStateName, NextState,
  -%%                              Timeout} |
  -%%                             {stop, Reason, NewState} |
  -%%                             {stop, Reason, Reply, NewState}
  -%% Description: Whenever a gen_fsm receives an event sent using
  -%% gen_fsm:sync_send_all_state_event/2,3, this function is called to handle
  -%% the event.
  -%%--------------------------------------------------------------------
  -handle_sync_event(_Event, _From, StateName, State) ->
  -    Reply = ok,
  -    {reply, Reply, StateName, State}.
  -
  -%%--------------------------------------------------------------------
  -%% Function:
  -%% handle_info(Info,StateName,State)-> {next_state, NextStateName, NextState}|
  -%%                                     {next_state, NextStateName, NextState,
  -%%                                       Timeout} |
  -%%                                     {stop, Reason, NewState}
  -%% Description: This function is called by a gen_fsm when it receives any
  -%% other message than a synchronous or asynchronous event
  -%% (or a system message).
  -%%--------------------------------------------------------------------
  -handle_info(_Info, StateName, State) ->
  -    {next_state, StateName, State}.
  -
  -%%--------------------------------------------------------------------
  -%% Function: terminate(Reason, StateName, State) -> void()
  -%% Description:This function is called by a gen_fsm when it is about
  -%% to terminate. It should be the opposite of Module:init/1 and do any
  -%% necessary cleaning up. When it returns, the gen_fsm terminates with
  -%% Reason. The return value is ignored.
  -%%--------------------------------------------------------------------
  -terminate(_Reason, _StateName, _State) ->
  +    {reply, Reply, State}.
  +
  +%%--------------------------------------------------------------------
  +%% Function: handle_cast(Msg, State) -> {noreply, State} |
  +%%                                      {noreply, State, Timeout} |
  +%%                                      {stop, Reason, State}
  +%% Description: Handling cast messages
  +%%--------------------------------------------------------------------
  +handle_cast(start_now, S) ->
  +    {ok, NextRequestTime, NS} = contact_tracker(S, "started"),
  +    {noreply, NS, timer:seconds(NextRequestTime)};
  +handle_cast(stop_now, S) ->
  +    {ok, NextRequestTime, NS} = contact_tracker(S, "stopped"),
  +    {noreply, NS, timer:seconds(NextRequestTime)};
  +handle_cast(torrent_completed, S) ->
  +    {ok, NextRequestTime, NS} = contact_tracker(S, "completed"),
  +    {noreply, NS, timer:seconds(NextRequestTime)}.
  +
  +%%--------------------------------------------------------------------
  +%% Function: handle_info(Info, State) -> {noreply, State} |
  +%%                                       {noreply, State, Timeout} |
  +%%                                       {stop, Reason, State}
  +%% Description: Handling all non call/cast messages
  +%%--------------------------------------------------------------------
  +handle_info(timeout, S) ->
  +    {ok, NextRequestTime, NS} = contact_tracker(S, none),
  +    {noreply, NS, timer:seconds(NextRequestTime)};
  +handle_info(Info, State) ->
  +    io:format("got info: ~p~n", [Info]),
  +    {noreply, State}.
  +
  +%%--------------------------------------------------------------------
  +%% Function: terminate(Reason, State) -> void()
  +%% Description: This function is called by a gen_server when it is about to
  +%% terminate. It should be the opposite of Module:init/1 and do any necessary
  +%% cleaning up. When it returns, the gen_server terminates with Reason.
  +%% The return value is ignored.
  +%%--------------------------------------------------------------------
  +terminate(Reason, _State) ->
  +    io:format("I am dying! ~p~n", [Reason]),
       ok.
   
   %%--------------------------------------------------------------------
  -%% Function:
  -%% code_change(OldVsn, StateName, State, Extra) -> {ok, StateName, NewState}
  +%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}
   %% Description: Convert process state when code is changed
   %%--------------------------------------------------------------------
  -code_change(_OldVsn, StateName, State, _Extra) ->
  -    {ok, StateName, State}.
  +code_change(_OldVsn, State, _Extra) ->
  +    {ok, State}.
   
   %%--------------------------------------------------------------------
   %%% Internal functions
  
positive.code:     end,
      {ok, RequestTime, S#state{trackerid = TrackerId}}.
  
  %% TODO: Can be made better yet, I am sure! Generalize into a proper code
  %%   construction.
  
  construct_headers([], HeaderLines) ->
      lists:concat(lists:reverse(HeaderLines));
  construct_headers([{Key, Value}], HeaderLines) ->
  
negative.code: 	   end,
      lists:concat([S#state.url, "?", construct_headers(EReq, [])]).
  
  %%% Tracker response lookup functions
  find_next_request_time(BC) ->
      {integer, R} = bcoding:search_dict_default({string, "interval"},
  