Refactor code to use state machine