Refactor stateful module to state module.