anchor.diff:              false
       end.
   
  -%% @doc Garbage collect the snapshot cache. 
  -snapshot_gc(SnapshotDict)-> 
  +%% @doc Garbage collection.
  +snapshot_insert_gc(Key, SnapshotDict, OpsDict, SnapshotCache, OpsCache)-> 
   	case (orddict:size(SnapshotDict))==?SNAPSHOT_THRESHOLD of 
   	true ->
   		lager:info("pruning the following snapshot cache: ~p",[SnapshotDict]),
  -		Pruned=orddict:from_list(lists:sublist(orddict:to_list(SnapshotDict), ?SNAPSHOT_THRESHOLD-?SNAPSHOT_MIN, ?SNAPSHOT_MIN)),
  -		lager:info("Result is: ",[Pruned]),
  -		Pruned;
  +		PrunedSnapshots=orddict:from_list(lists:sublist(orddict:to_list(SnapshotDict), 1+?SNAPSHOT_THRESHOLD-?SNAPSHOT_MIN, ?SNAPSHOT_MIN)),
  +		lager:info("Result is: ~p",[PrunedSnapshots]),
  +		FirstOp=lists:nth(1, PrunedSnapshots),
  +		{CommitTime, _S} = FirstOp,
  +		lager:info("pruning the following OPERATIONS cache before commit time: ~p ~n ~p",[CommitTime,OpsDict]),
  +		PrunedOps=prune_ops(OpsDict, CommitTime),
  +		lager:info("Result is: ~p",[PrunedOps]),
  +		ets:insert(SnapshotCache, {Key, PrunedSnapshots}),
  +        ets:insert(OpsCache, {Key, PrunedOps}),
  +        true;
   	false ->
  +		ets:insert(SnapshotCache, {Key, SnapshotDict}),
   		lager:info("NO NEED OF pruning the following snapshot cache: ~p",[SnapshotDict]),
  -		SnapshotDict
  +		false
   	end.
  +	
  +%% @doc Remove from OpsDict all operations that have committed before Threshold. 	
  +prune_ops(OpsDict, Threshold)->
  +	orddict:filter(fun(_Key, Value) -> 
  +				lager:info("This is the operation to analyse: ~n ~p", [Value]),
  +				(belongs_to_snapshot(Threshold,(lists:last(Value))#clocksi_payload.snapshot_time)) end, OpsDict).
  +
   
   %% @doc Garbage collect the operations cache. 
   ops_gc(OpsDict)-> 
  
positive.code: -spec belongs_to_snapshot({Dc::term(),CommitTime::non_neg_integer()},
                          SnapshotTime::vectorclock:vectorclock()) -> boolean().
  belongs_to_snapshot({Dc, CommitTime}, SnapshotTime) ->
      case vectorclock:get_clock_of_dc(Dc, SnapshotTime) of
          {ok, Ts} ->
              lager:info("materialiser_vnode: CommitTime: ~p SnapshotTime: ~p Result: ~p",
  
negative.code:         end
  	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, []).
  