anchor.diff:  state_to_record(FileName, SearchPaths, TabWidth, SM) ->
       {ok, {_,  ModInfo}} = refac_util:parse_annotate_file(FileName, true, SearchPaths, TabWidth),
       {value, {module, ModName}} = lists:keysearch(module, 1, ModInfo),
  -  
  +    case is_statemachine_used(ModInfo, SM) of
  +	true ->
  +	    check_current_state_type(FileName, ModName, ModInfo, SM);
  +	{error, Msg}-> throw({error, Msg})
  +    end.
  +
   
   state_to_record_1(FileName, RecordName, RecordFields, StateFuns, IsTuple, SM, SearchPaths, TabWidth, Editor, Cmd) ->
       {ok, {AnnAST, Info}} = refac_util:parse_annotate_file(FileName, true, SearchPaths, TabWidth),
  
positive.code: 
  
  do_state_to_record(ModName, ModInfo,  AnnAST, RecordName, RecordFields, StateFuns, RecordExists, IsTuple, SM) ->
      {ok, {AnnAST,  ModInfo}} = refac_util:parse_annotate_file(FileName, true, SearchPaths, TabWidth),
      {value, {module, ModName}} = lists:keysearch(module, 1, ModInfo),
      Forms = refac_syntax:form_list_elements(AnnAST),
      Funs = [],
      TupleToRecordFunName = tuple_to_record_fun_name(ModInfo, Funs, RecordName, RecordFields),
      RecordToTupleFunName = record_to_tuple_fun_name(ModInfo, Funs, RecordName, RecordFields),
      Fun = fun (F) ->
  
negative.code:     wrap_fun_interface_in_return(Form1, ModName, RecordName, RecordFields, IsTuple, StateFuns, SM,
  				TupleToRecordFunName, RecordToTupleFunName).
  
  wrap_fun_interface_in_return(Form, ModName, RecordName, RecordFields,IsTuple, StateFuns, SM,
  			    TupleToRecordFunName, RecordToTupleFunName) ->
      Fun= fun(Node, _Others) ->
  		 case is_callback_fun_app(Node, ModName, StateFuns, SM) of
  		     {true, _PatIndex, true} ->
  			 case SM of 
  			     gen_fsm ->
  				 throw({error, "Callback functions are called as normal functions."});
  			     _ ->
  				 make_record_to_tuple_app(Node, RecordName, RecordFields, IsTuple,
  							 TupleToRecordFunName, RecordToTupleFunName)
  			 end;
  		     false ->
  			 Node
  		 end
  	 end,
      Form1 = refac_util:full_buTP(Fun, Form, {}),
      case SM of
  	gen_fsm ->
  	    Form1;
  	_ -> 
  	    Res = check_use_of_run_commands(Form1, SM),
  	    case Res of
  		[] -> Form1;
  		_ ->
  		    {Form2, _} =refac_util:stop_tdTP(fun wrap_run_commands_result/2, Form1,
  						     {RecordName, RecordFields, Res, IsTuple, 
  						      refac_unfold_fun_app:collect_vars(Form1),SM}),
  		    Form2
  	    end
      end.
  
  check_use_of_run_commands(Form, SM) ->
  