moved state_machine out to a tmp file