Nicer state switching

State switching now works better in general. We may yet want to refactor the various
states so that state switching is more automatic and less dependent on the quirks of State
subclasses.