Refactor SCC code to use an actual state machine