Refactor module StateMachines.