anchor.diff:  handle_call({trace, Type, Message}, _From, #state{trace=Trace0}=State) ->
       %% lager:info("~p: recording trace type: ~p message: ~p", [?MODULE, Type, Message]),
       {reply, ok, State#state{trace=Trace0++[{Type, Message}]}};
  -handle_call({replay, Type, Message}, _From, #state{previous_trace=PreviousTrace, replay=Replay}=State) ->
  +handle_call({replay, Type, Message}, From, #state{previous_trace=PreviousTrace0, replay=Replay, blocked_processes=BlockedProcesses0}=State) ->
       case Replay of 
           true ->
  -            [{NextType, NextMessage}|Rest] = PreviousTrace, 
  -
  -            lager:info("~p: ******************************************************", [?MODULE]),
  -
  -            lager:info("~p: in replay for message ~p", [?MODULE, {Type, Message}]),
  -
  -            case {Type, Message} of 
  -                {NextType, NextMessage} ->
  -                    lager:info("~p: received expected message!", [?MODULE]),
  -                    ok;
  -                {_, _} ->
  -                    lager:info("~p: DID NOT RECEIVE expected message: expected: ~p, got: ~p", 
  -                               [?MODULE, {NextType, NextMessage}, {Type, Message}]),
  -                    case lists:member({NextType, NextMessage}, PreviousTrace) of 
  -                        true ->
  -                            lager:info("~p: message is scheduled for future delivery, blocking!", [?MODULE]),
  -                            ok;
  -                        false ->
  -                            lager:info("~p: message should not have arrived!", [?MODULE]),
  -                            ok
  -                    end
  -            end,
  -
  -            lager:info("~p: ******************************************************", [?MODULE]),
  -
  -            {reply, ok, State#state{previous_trace=Rest}};
  +            %% Find next message that should arrive based on the trace.
  +            %% Can we process immediately?
  +            case can_deliver_based_on_trace({Type, Message}, PreviousTrace0) of 
  +                true ->
  +                    %% Deliver as much as we can.
  +                    {PreviousTrace, BlockedProcesses} = trace_deliver(PreviousTrace0, BlockedProcesses0),
  +
  +                    %% Record new trace position and new list of blocked processes.
  +                    {reply, ok, State#state{blocked_processes=BlockedProcesses, previous_trace=PreviousTrace}};
  +                false ->
  +                    %% If not, store message, block caller until processed.
  +                    BlockedProcesses = [{{Type, Message}, From} | BlockedProcesses0],
  +
  +                    %% Block the process.
  +                    {noreply, State#state{blocked_processes=BlockedProcesses}}
  +            end;
           false ->
               {reply, ok, State}
       end;
  
positive.code: 
  %%%===================================================================
  %%% Internal functions
  %%%===================================================================
negative.code: -record(state, {previous_trace=[],
                  trace=[], 
                  replay=false,
                  blocked_processes=[],
                  identifier=undefined}).
  
  -define(FILENAME, "/tmp/partisan.trace").
  