anchor.diff:                              preflist=Preflist,
                               from=From,
                               opid=OpId}) ->
  +    lager:info("Executing operation: ~p", [Type]),
       case Type of
           append ->
  -            lager:info("FSM: Replicate append ~n"),
               logging_vnode:dappend(Preflist, LogId, OpId, Payload),
  -            SD1 = SD0#state{num_to_ack=?NUM_W},
  -            {next_state, wait_append, SD1, ?COMM_TIMEOUT};
  +            {next_state, wait_append, SD0#state{num_to_ack=?NUM_W},
  +             ?COMM_TIMEOUT};
           read ->
  -            lager:info("FSM: Replication read ~n"),
               logging_vnode:dread(Preflist, LogId),
  -            SD1 = SD0#state{num_to_ack=?NUM_R},
  -            {next_state, wait_read, SD1, ?COMM_TIMEOUT};
  -        _ ->
  -            lager:info("FSM: Wrong command ~n"),
  +            {next_state, wait_read, SD0#state{num_to_ack=?NUM_R},
  +             ?COMM_TIMEOUT};
  +        _ ->
               floppy_coord_fsm:finish_op(From, error, wrong_command),
  -            %%reply message to user
               {stop, normal, SD0}
       end.
   
  -
   %% @doc Waits for W write reqs to respond.
  -wait_append({ok,{_Node, OpId}}, SD=#state{type=Type, from=From, num_to_ack= NumToAck}) ->
  +wait_append({ok, {_Node, OpId}},
  +            SD=#state{from=From, num_to_ack=NumToAck}) ->
       case NumToAck of
           1 ->
  -            lager:info("FSM: Finish collecting replies for ~w ~n", [Type]),
  +            lager:debug("All replies received."),
               floppy_coord_fsm:finish_op(From, ok, OpId),
               {stop, normal, SD};
           _ ->
  -            lager:info("FSM: Keep collecting replies~n"),
  -            {next_state, wait_append, SD#state{num_to_ack= NumToAck-1 }, ?COMM_TIMEOUT}
  +            {next_state, wait_append, SD#state{num_to_ack=NumToAck-1},
  +             ?COMM_TIMEOUT}
       end;
   
   wait_append({error, Reason}, SD=#state{from=From, error_msg=ErrorMsg}) ->
       ErrorMsg1 = [Reason|ErrorMsg],
  -    lager:info("FSM: Error in append: ~w", [Reason]),
       case length(ErrorMsg1) of
           ?W_ERROR_THRESHOLD ->
               floppy_coord_fsm:finish_op(From, error, ErrorMsg1),
               {stop, normal, SD};
           _ ->
  -            {next_state, wait_append, SD#state{error_msg=ErrorMsg}, ?COMM_TIMEOUT}
  +            {next_state, wait_append, SD#state{error_msg=ErrorMsg},
  +             ?COMM_TIMEOUT}
       end;
   
   wait_append(timeout, SD=#state{from=From}) ->
  -    lager:info("FSM: Error in append: timeout"),
       floppy_coord_fsm:finish_op(From, error, quorum_unreachable),
       {stop, normal, SD}.
   
   %% @doc Waits for R read reqs to respond and union returned operations.
  -%% Then send vnodes operations if they haven't seen some.
  -%% Finally reply the unioned operation list to the coord fsm.
  -wait_read({ok, {Node, Result}}, SD=#state{type=Type, from= From, node_ops = NodeOps, log_id=LogId, readresult= ReadResult , num_to_ack= NumToAck}) ->
  +%%      Then send vnodes operations if they haven't seen some.
  +%%      Finally reply the unioned operation list to the coord fsm.
  +wait_read({ok, {Node, Result}}, SD=#state{from=From,
  +                                          node_ops=NodeOps,
  +                                          log_id=LogId,
  +                                          readresult=ReadResult,
  +                                          num_to_ack=NumToAck}) ->
       NodeOps1 = lists:append([{Node, Result}], NodeOps),
       Result1 = union_ops(ReadResult, [], Result),
  -    case NumToAck of 
  -        1 -> 
  -            lager:info("FSM: Finish reading for ~w ~w ~n", [Type, LogId]),
  -                repair(NodeOps1, Result1, LogId),
  -                floppy_coord_fsm:finish_op(From, ok, Result1),	
  -                {next_state, repair_rest, SD#state{num_to_ack = ?N-?NUM_R, node_ops=NodeOps1, readresult = Result1}, ?COMM_TIMEOUT};
  -            _ ->
  -            lager:info("FSM: Keep collecting replies~n"),
  -            {next_state, wait_read, SD#state{num_to_ack= NumToAck-1, node_ops= NodeOps1, readresult = Result1}, ?COMM_TIMEOUT}
  +    case NumToAck of
  +        1 ->
  +            repair(NodeOps1, Result1, LogId),
  +            floppy_coord_fsm:finish_op(From, ok, Result1),
  +            {next_state, repair_rest, SD#state{num_to_ack=?N-?NUM_R,
  +                                               node_ops=NodeOps1,
  +                                               readresult=Result1},
  +             ?COMM_TIMEOUT};
  +        _ ->
  +            {next_state, wait_read, SD#state{num_to_ack=NumToAck-1,
  +                                             node_ops=NodeOps1,
  +                                             readresult=Result1},
  +             ?COMM_TIMEOUT}
       end;
   
   wait_read({error, Reason}, SD=#state{from=From, error_msg=ErrorMsg}) ->
       ErrorMsg1 = [Reason|ErrorMsg],
  -    lager:info("FSM: Error in read: ~w", [Reason]),
  +    lager:info("Error in performing read operation: ~p", [Reason]),
       case length(ErrorMsg1) of
           ?R_ERROR_THRESHOLD ->
  -                floppy_coord_fsm:finish_op(From, error, ErrorMsg1),
  -                {stop, normal, SD};
  -        _ ->
  -            {next_state, wait_read, SD#state{error_msg=ErrorMsg}, ?COMM_TIMEOUT}
  +            floppy_coord_fsm:finish_op(From, error, ErrorMsg1),
  +            {stop, normal, SD};
  +        _ ->
  +            {next_state, wait_read, SD#state{error_msg=ErrorMsg},
  +             ?COMM_TIMEOUT}
       end;
   
   wait_read(timeout, SD=#state{from=From}) ->
  -    lager:info("FSM: Error in read: timeout"),
  +    lager:info("Read timeout!"),
       floppy_coord_fsm:finish_op(From, error, quorum_unreachable),
       {stop, normal, SD}.
   
  -%% @doc Keeps waiting for read replies from vnodes after replying to coord fsm.
  -%% Do read repair if any of them haven't seen some ops.
  -repair_rest(timeout, SD= #state{node_ops=NodeOps, readresult = ReadResult, log_id=LogId}) ->
  -    lager:info("FSM: read repair timeout! Start repair anyway~n"),
  +%% @doc Keeps waiting for read replies from vnodes after replying to
  +%%      coord fsm.
  +%%      Do read repair if any of them haven't seen some ops.
  +repair_rest(timeout,
  +            SD=#state{node_ops=NodeOps, readresult=ReadResult,
  +                      log_id=LogId}) ->
  +    lager:debug("FSM: read repair timeout! Start repair anyway~n"),
       repair(NodeOps, ReadResult, LogId),
       {stop, normal, SD};
   
  -repair_rest({ok, {Node, Result}}, SD=#state{num_to_ack = NumToAck, node_ops = NodeOps, readresult = ReadResult, log_id=LogId}) ->
  +repair_rest({ok, {Node, Result}},
  +            SD=#state{num_to_ack=NumToAck, node_ops=NodeOps,
  +                      readresult=ReadResult, log_id=LogId}) ->
       NodeOps1 = lists:append([{Node, Result}], NodeOps),
       Result1 = union_ops(ReadResult, [], Result),
  -    case NumToAck of 
  -        1 -> 
  -            lager:info("FSM: Finish collecting replies, start read repair ~n"),
  -                repair(NodeOps, ReadResult, LogId),
  -                {stop, normal, SD};
  -        _ ->
  -            lager:info("FSM: Keep collecting replies~n"),
  -            {next_state, repair_rest, SD#state{num_to_ack= NumToAck-1, node_ops= NodeOps1, readresult = Result1}, ?COMM_TIMEOUT}
  +    case NumToAck of
  +        1 ->
  +            repair(NodeOps, ReadResult, LogId),
  +            {stop, normal, SD};
  +        _ ->
  +            {next_state, repair_rest, SD#state{num_to_ack=NumToAck-1,
  +                                               node_ops=NodeOps1,
  +                                               readresult=Result1},
  +             ?COMM_TIMEOUT}
       end;
   
   repair_rest({error, Reason}, SD) ->
  -    lager:info("FSM: Error in read repair: ~w", [Reason]),
  +    lager:info("Error in read repair: ~p", [Reason]),
       {next_state, repair_rest, SD, ?COMM_TIMEOUT}.
   
   handle_info(_Info, _StateName, StateData) ->
  -    {stop,badmsg,StateData}.
  +    {stop, badmsg, StateData}.
   
   handle_event(_Event, _StateName, StateData) ->
  -    {stop,badmsg,StateData}.
  +    {stop, badmsg, StateData}.
   
   handle_sync_event(_Event, _From, _StateName, StateData) ->
  -    {stop,badmsg,StateData}.
  -
  -code_change(_OldVsn, StateName, State, _Extra) -> 
  +    {stop ,badmsg, StateData}.
  +
  +code_change(_OldVsn, StateName, State, _Extra) ->
       {ok, StateName, State}.
   
   terminate(_Reason, _StateName, _StateData) ->
  
positive.code:     end.
  
  %% @doc Remove duplicate ops with OpId from a list (the first param)
  %% and return a list with only one operation with OpId
  -spec remove_dup([{_,operation()}],op_id(),[{_,operation()}]) -> [{_,operation()}].
  remove_dup([], _OpId, Set2) ->
      Set2;
  remove_dup([H|T], OpId, Set2) ->
      {_, #operation{op_number= OpNum}} = H,
      Set3 = case OpNum /= OpId of
                true -> lists:append(Set2, [H]);
                false -> Set2
             end,
      remove_dup(T, OpId, Set3).
  
  
  -ifdef(TEST).
  union_test()->
  
negative.code: %% @doc Find operations that are in List2 but not in List1
  -spec find_diff_ops(list(),list()) -> list().
  find_diff_ops(List1, List2) ->
      lists:filter(fun(X)-> lists:member(X, List1) == false end, List2).
  
  %% @doc Make a union of operations in L1 and L2
  -spec union_ops([{_,operation()}],[{_,operation()}],[{_,operation()}]) ->
      [{_,operation()}].
  union_ops(L1, L2, []) ->
      lists:append(L1, L2);
  union_ops(L1, L2, [Op|T]) ->
      {_, #operation{op_number=OpId}} = Op,
      L3 = remove_dup(L1, OpId,[]),
      L4 = lists:append(L2, [Op]),
      union_ops(L3, L4, T).
  