Improvements to the switch pattern state machine