anchor.diff:      ?TLOGN("aborting transaction ~p", [TransactionID]),
       TransLog = tp_log:get_log(State),
       TransLogUndecided = TransLog#translog.undecided,
  -    IsLogged = gb_trees:is_defined(TransactionID, TransLogUndecided), 
  -    if
  -	IsLogged == true ->
  +    case gb_trees:is_defined(TransactionID, TransLogUndecided) of
  +	true ->
   	    LogEntries = gb_trees:get(TransactionID, TransLogUndecided),
   	    tp_abort_unlock(LogEntries),
   	    NewTransLog = tp_log:get_log(State),
   	    tp_log:remove_from_undecided(State, TransactionID, NewTransLog, TransLogUndecided);
  -	true ->
  +	_Any ->
   	    %%get information about transaction --- might have missed something before
   	    State
       end.
  
positive.code: tp_commit_store_unlock([]) ->
      ok;
  tp_commit_store_unlock([Entry | LogRest])->
      if 
  	Entry#logentry.operation == write ->
  	    ?DB:write(Entry#logentry.rkey, Entry#logentry.value, Entry#logentry.version),
  	    %_Stored = ?DB:read(Entry#logentry.rkey),
  	    ?DB:unset_write_lock(Entry#logentry.rkey);
  	true ->
  	    ?DB:unset_read_lock(Entry#logentry.rkey)
      end,
      
  
negative.code: tp_validate(State, Tid, Item)->
      %?TLOGN("validating item ~p", [Item]),
      %% Check whether the version is still valid
      LockRes = case ?DB:read(Item#item.rkey) of
  		  {ok, _Value, Version} ->
  		      set_lock(check_version(Item, Version), Item);
  		  _Any ->
  		      case Item#item.operation of
  			  write ->
  			      set_lock(success, Item);
  			  _Any ->
  			      failed
  		      end    
  	      end,
      Decision = decision(LockRes),
      NewState = update_transaction_participant_log(State, Tid, Item, Decision),
      NewVote = trecords:new_vote(Tid, Item#item.key, Item#item.rkey, Decision, 1),   
      tsend:send_vote_to_rtms(Item#item.tms, NewVote),
      NewState.
      
  
  set_lock(success, #item{operation=read} = Item) ->
      ?DB:set_read_lock(Item#item.rkey);
  set_lock(success, #item{operation=write} = Item) ->
      ?DB:set_write_lock(Item#item.rkey);
  set_lock(_LockFailed, _Item)->
      failed.
  
  decision(ok)->
      prepared;
  decision(_)->
      abort.
  
  update_transaction_participant_log(State, Tid, Item, prepared) ->
      update_state(State, Tid, tp_log:new_logentry(prepared, Tid, Item));
  update_transaction_participant_log(State, Tid, Item, abort) ->
      update_state(State, Tid, tp_log:new_logentry(local_abort, Tid, Item)).
  
  update_state(OldState, Tid, LogEntry)->
      tp_log:add_to_undecided(OldState, Tid, LogEntry).
      
  check_version(#item{operation=read} = TransactionItem, Version)-> 
       if
  	 TransactionItem#item.version >= Version ->   
  	     success;
  	 true ->
  	     fail
       end;
  check_version(#item{operation=write} = TransactionItem, Version)-> 
      if
  	TransactionItem#item.version == (Version + 1) ->
  	    success;
  	true ->
  	    fail
      end.
  
  tp_commit(State, TransactionID)->
      %?TLOGN("committing transaction ~p", [TransactionID]),
      TransLog = tp_log:get_log(State),
      TransLogUndecided = TransLog#translog.undecided, 
      case gb_trees:is_defined(TransactionID, TransLogUndecided) of
  	true ->
  	    LogEntries = gb_trees:get(TransactionID, TransLogUndecided),
  	    tp_commit_store_unlock(LogEntries),
  	    NewTransLog = tp_log:get_log(State),
  	    tp_log:remove_from_undecided(State, TransactionID, NewTransLog, TransLogUndecided);
  	_Any ->
  	    %%get information about transaction --- might have missed something before
  	    State
      end.
  