Move state_machine definition and related methods to a separate file.