Implemented poor-mans pattern matching for states.