Refactor plugin initialization and state transition.