Replace the state hacks with stateless case expression handling.