anchor.diff:  
   %%---------------- Internal Functions -------------------%%
   
  -%% @doc This function takes care of reading. It is implemented here for not blocking the 
  -%% vnode when the write function calls it. That is done for garbage collection. 
  +%% @doc This function takes care of reading. It is implemented here for not blocking the
  +%% vnode when the write function calls it. That is done for garbage collection.
   -spec internal_read(term(),term(), atom(), vectorclock:vectorclock(), atom() , atom() ) -> ok.
   internal_read(Sender, Key, Type, SnapshotTime, OpsCache, SnapshotCache) ->
  -    % get the latest snapshot for the key
  +                                                % get the latest snapshot for the key
       case ets:lookup(SnapshotCache, Key) of
  -    	[] ->
  -    		NewSnapshot=clocksi_materializer:new(Type),
  +        [] ->
  +            NewSnapshot=clocksi_materializer:new(Type),
               case ets:lookup(OpsCache, Key) of
  -            [] ->
  -            	riak_core_vnode:reply(Sender, {ok, NewSnapshot});
  -            [{_, OpsDict}] ->
  -            	{ok, Ops}= filter_ops(OpsDict),
  -            	LastOp=lists:last(Ops),
  -            	TxId = LastOp#clocksi_payload.txid,
  -            	{ok, Snapshot, CommitTime} = clocksi_materializer:materialize(Type, NewSnapshot, SnapshotTime, [LastOp], TxId),
  -            	riak_core_vnode:reply(Sender, {ok, Snapshot}),
  -            	SnapshotDict=orddict:new(),
  -            	ets:insert(SnapshotCache, {Key, orddict:store(CommitTime,Snapshot, SnapshotDict)})
  +                [] ->
  +                    riak_core_vnode:reply(Sender, {ok, NewSnapshot});
  +                [{_, OpsDict}] ->
  +                    {ok, Ops}= filter_ops(OpsDict),
  +                    LastOp=lists:last(Ops),
  +                    TxId = LastOp#clocksi_payload.txid,
  +                    {ok, Snapshot, CommitTime} = clocksi_materializer:materialize(Type, NewSnapshot, SnapshotTime, [LastOp], TxId),
  +                    riak_core_vnode:reply(Sender, {ok, Snapshot}),
  +                    SnapshotDict=orddict:new(),
  +                    ets:insert(SnapshotCache, {Key, orddict:store(CommitTime,Snapshot, SnapshotDict)})
               end;
  -        [{_, SnapshotDict}] -> 
  +        [{_, SnapshotDict}] ->
               case get_latest_snapshot(SnapshotDict, SnapshotTime) of
  -			{ok, {_SnapshotCommitTime, LatestSnapshot}}->
  -				case ets:lookup(OpsCache, Key) of
  -				[] ->
  -					riak_core_vnode:reply(Sender, {ok, LatestSnapshot});
  -				[{_, OpsDict}] ->
  -					{ok, Ops}= filter_ops(OpsDict),
  -					case Ops of
  -					[] ->
  -						riak_core_vnode:reply(Sender, {ok, LatestSnapshot});
  -					[H|T] ->
  -						LastOp=lists:last([H|T]),
  -						TxId = LastOp#clocksi_payload.txid,
  -						{ok, Snapshot, CommitTime} = clocksi_materializer:materialize(Type, LatestSnapshot, SnapshotTime, [LastOp], TxId),
  -						case (Sender /= ignore) of
  -						true ->
  -							riak_core_vnode:reply(Sender, {ok, Snapshot});
  -						false ->
  -							false
  -						end,
  -						SnapshotDict1=orddict:store(CommitTime,Snapshot, SnapshotDict),
  -						snapshot_insert_gc(Key,SnapshotDict1, OpsDict, SnapshotCache, OpsCache)
  -					end
  -				end;
  -			{error, no_snapshot} ->
  -				%%FIX THIS, READ FROM THE LOG WHEN THERE IS NO SNAPSHOT.
  -				riak_core_vnode:reply(Sender, {error, no_snapshot})
  -			end	
  +                {ok, {_SnapshotCommitTime, LatestSnapshot}}->
  +                    case ets:lookup(OpsCache, Key) of
  +                        [] ->
  +                            riak_core_vnode:reply(Sender, {ok, LatestSnapshot});
  +                        [{_, OpsDict}] ->
  +                            {ok, Ops}= filter_ops(OpsDict),
  +                            case Ops of
  +                                [] ->
  +                                    riak_core_vnode:reply(Sender, {ok, LatestSnapshot});
  +                                [H|T] ->
  +                                    LastOp=lists:last([H|T]),
  +                                    TxId = LastOp#clocksi_payload.txid,
  +                                    {ok, Snapshot, CommitTime} = clocksi_materializer:materialize(Type, LatestSnapshot, SnapshotTime, [LastOp], TxId),
  +                                    case (Sender /= ignore) of
  +                                        true ->
  +                                            riak_core_vnode:reply(Sender, {ok, Snapshot});
  +                                        false ->
  +                                            false
  +                                    end,
  +                                    SnapshotDict1=orddict:store(CommitTime,Snapshot, SnapshotDict),
  +                                    snapshot_insert_gc(Key,SnapshotDict1, OpsDict, SnapshotCache, OpsCache)
  +                            end
  +                    end;
  +                {error, no_snapshot} ->
  +                    %%FIX THIS, READ FROM THE LOG WHEN THERE IS NO SNAPSHOT.
  +                    riak_core_vnode:reply(Sender, {error, no_snapshot})
  +            end
       end,
       ok.
  -	%TODO: trigger the GC mechanism asynchronously
  -	
  -	
  +                                                %%TODO: trigger the GC mechanism asynchronously
  +
  +
   %% @doc This function takes care of appending an operation to the log and
  -%%  to the cache.	
  --spec internal_update(term(), Key::term(), DownstreamOp::clocksi_payload(), 
  -		OpsCache::atom(), SnapshotCache::atom()) ->	ok.
  -internal_update(Sender, Key, DownstreamOp, OpsCache, SnapshotCache) ->	
  -%% TODO: Remove unnecessary information from op_payload in log_Record
  +%%  to the cache.
  +-spec internal_update(term(), Key::term(), DownstreamOp::clocksi_payload(),
  +                      OpsCache::atom(), SnapshotCache::atom()) ->	ok.
  +internal_update(Sender, Key, DownstreamOp, OpsCache, SnapshotCache) ->
  +    %% TODO: Remove unnecessary information from op_payload in log_Record
       LogRecord = #log_record{tx_id=DownstreamOp#clocksi_payload.txid,
                               op_type=downstreamop,
                               op_payload=DownstreamOp},
  
positive.code:     %% TODO: what if all of the following was done asynchronously?
      case logging_vnode:append(Node,LogId,LogRecord) of
          {ok, _} ->
          	riak_core_vnode:reply(Sender, ok),
          	case ets:lookup(OpsCache, Key) of
          	[]->
          		OpsDict=orddict:new();
          	[{_, OpsDict}]->
          		OpsDict
          	end,        	
          	op_insert_gc(Key,DownstreamOp, OpsDict, OpsCache, SnapshotCache),
              ok;
          {error, Reason} ->
              riak_core_vnode:reply(Sender, {error, Reason})
      end.
  
  
  %% @doc Obtains, from an orddict of Snapshots, the latest snapshot that can be included in 
  %% a snapshot identified by SnapshotTime
  -spec get_latest_snapshot(SnapshotDict::orddict:orddict(), SnapshotTime::vectorclock:vectorclock())
  	 -> {ok, term()} | {error, no_snapshot}| {error, wrong_format, term()}.
  get_latest_snapshot(SnapshotDict, SnapshotTime) ->
  	case SnapshotDict of
  	[]->
  		{ok,[]};
  	[H|T]->
  		case orddict:filter(fun(Key, _Value) -> 
  				belongs_to_snapshot(Key, SnapshotTime) end, [H|T]) of 
  			[]->
  		        {error,no_snapshot};
  		    [H1|T1]->
  				{CommitTime, Snapshot} = lists:last([H1|T1]),
  				{ok, {CommitTime, Snapshot}}
          end;
      Anything ->
      	{error, wrong_format, Anything}
  	end.
  
  %% @doc Get a list of operations from an orddict of operations
  -spec filter_ops(orddict:orddict()) -> {ok, list()} | {error, wrong_format}.
  filter_ops(Ops) ->
  	filter_ops(Ops, []).
  -spec filter_ops(orddict:orddict(), list()) -> {ok, list()} | {error, wrong_format}.
  filter_ops([], Acc) ->
  	{ok, Acc};
  filter_ops([H|T], Acc) ->
  	case H of 
  	{_Key, Ops} ->
  		filter_ops(T,lists:append(Acc, Ops));
  	_ ->
  		{error, wrong_format}
  	end;
  filter_ops(_, _Acc) ->
  	{error, wrong_format}.
  	
      
  %% @doc Check whether a Key's operation or stored snapshot is included
  %%		in a snapshot defined by a vector clock
  %%      Input: Dc = Datacenter Id
  
negative.code:     {ok, #state{partition=Partition, ops_cache=OpsCache, snapshot_cache=SnapshotCache}}.
  
  handle_command({read, Key, Type, SnapshotTime}, Sender,
                 State = #state{ops_cache=OpsCache, snapshot_cache=SnapshotCache}) ->
      ok=internal_read(Sender, Key, Type, SnapshotTime, OpsCache, SnapshotCache),
      {noreply, State};
  
  handle_command({update, Key, DownstreamOp}, Sender,
                 State = #state{ops_cache = OpsCache, snapshot_cache=SnapshotCache})->
      ok=internal_update(Sender, Key, DownstreamOp, OpsCache, SnapshotCache),
      {noreply, State};
  
  handle_command(_Message, _Sender, State) ->
      {noreply, State}.
  
  