Refactor the state transition to improve readability