anchor.diff:      end.
   
   %% @doc	get_log_from_map:	abstracts the get function of a key-value store
  -%%							currently using dict
  -%%		Input:	Map:	dict that representes the map
  -%%				LogId:	identifies the log.
  -%%		Return:	The actual name of the log
  --spec get_log_from_map(dict(), LogId::[Index::integer()]) -> {ok, term()} | {error, no_log_for_preflist}.
  +%%              currently using dict
  +%%      Input:  Map:  dict that representes the map
  +%%              LogId:  identifies the log.
  +%%      Return: The actual name of the log
  +-spec get_log_from_map(dict(), [integer()]) ->
  +    {ok, term()} | {error, no_log_for_preflist}.
   get_log_from_map(Map, LogId) ->
  -	case dict:find(LogId, Map) of
  -		{ok, Log} ->
  -			{ok, Log};
  -		error ->
  -			lager:info("Preflist to map return: no_log_for_preflist: ~w~n",[LogId]),
  -			{error, no_log_for_preflist}
  -	end.
  -
  -%% @doc         join_logs: Recursive fold of all the logs stored in the vnode
  -%%              Input:  Logs: A list of pairs {Preflist, Log}
  -%%                              F: Function to apply when floding the log (dets)
  -%%                              Acc: Folded data
  -%%              Return: Folded data of all the logs.
  --spec join_logs(Map::[{preflist(), log()}], F::fun(), Acc::term()) -> term().
  -join_logs([], _F, Acc) -> Acc;
  -join_logs([Element|Rest], F, Acc) ->
  -    {_Preflist, Log} = Element,
  +    case dict:find(LogId, Map) of
  +        {ok, Log} ->
  +            {ok, Log};
  +        error ->
  +            lager:info("Preflist to map return: no_log_for_preflist: ~w~n",
  +                       [LogId]),
  +            {error, no_log_for_preflist}
  +    end.
  +
  +%% @doc join_logs: Recursive fold of all the logs stored in the vnode
  +%%      Input:  Logs: A list of pairs {Preflist, Log}
  +%%                      F: Function to apply when floding the log (dets)
  +%%                      Acc: Folded data
  +%%      Return: Folded data of all the logs.
  +-spec join_logs([{preflist(), log()}], fun(), term()) -> term().
  +join_logs([], _F, Acc) ->
  +    Acc;
  +join_logs([{_Preflist, Log}|T], F, Acc) ->
       JointAcc = dets:foldl(F, Acc, Log),
  -    join_logs(Rest, F, JointAcc).
  -
  -%% @doc	insert_operation: Inserts an operation into the log only if the OpId is not already in the log
  -%%		Input:	Log: The identifier log the log where the operation will be inserted
  -%%				LogId: Log identifier to which the operation belongs.
  -%%				OpId: Id of the operation to insert
  -%%				Payload: The payload of the operation to insert
  -%%		Return:	{ok, OpId} | {error, Reason}
  --spec insert_operation(log(), [Index::integer()], op_id(), payload()) -> {ok, op_id()} | {error, reason()}.
  +    join_logs(T, F, JointAcc).
  +
  +%% @doc insert_operation: Inserts an operation into the log only if the 
  +%%      OpId is not already in the log
  +%%      Input:
  +%%          Log: The identifier log the log where the operation will be 
  +%%               inserted
  +%%          LogId: Log identifier to which the operation belongs.
  +%%          OpId: Id of the operation to insert
  +%%          Payload: The payload of the operation to insert
  +%%      Return: {ok, OpId} | {error, Reason}
  +-spec insert_operation(log(), [integer()], op_id(), payload()) ->
  +    {ok, op_id()} | {error, reason()}.
   insert_operation(Log, LogId, OpId, Payload) ->
       case dets:match(Log, {LogId, #operation{op_number=OpId, payload='_'}}) of
           [] ->
  -            Result = dets:insert(Log,{LogId, #operation{op_number=OpId,payload=Payload}}),
  -            Response = case Result of
  -                           ok ->
  -                               {ok, OpId};
  -                           {error, Reason} ->
  -                               {error, Reason}
  -                       end,
  -            Response;
  +            Result = dets:insert(Log, {LogId, #operation{op_number=OpId,
  +                                                         payload=Payload}}),
  +            case Result of
  +                ok ->
  +                    {ok, OpId};
  +                {error, Reason} ->
  +                    {error, Reason}
  +            end;
           {error, Reason} ->
               {error, Reason};
           _ ->
  
positive.code:             {reply, {error, Reason}, State}
      end;
  
  %% @doc Threshold read command: Returns the operations logged for Key from a specified op_id-based threshold
  %%	    Input:  From: the oldest op_id to return
  %%              LogId: Identifies the log to be read
  %%	    Output: {vnode_id, Operations} | {error, Reason}
  handle_command({threshold_read, LogId, From}, _Sender, #state{partition=Partition, logs_map=Map}=State) ->
      case get_log_from_map(Map, LogId) of
          {ok, Log} ->
              case get_log(Log, LogId) of
  
negative.code:     {reply, Result, State};
  
  %% @doc Append command: Appends a new op to the Log of Key
  %%      Input:  LogId: Indetifies which log the operation has to be
  %%              appended to.
  %%              Payload of the operation
  %%              OpId: Unique operation id
  %%      Output: {ok, {vnode_id, op_id}} | {error, Reason}
  handle_command({append, LogId, OpId, Payload}, _Sender,
                 #state{logs_map=Map, partition=Partition}=State) ->
      case get_log_from_map(Map, LogId) of
          {ok, Log} ->
              case insert_operation(Log, LogId, OpId, Payload) of
  