More state machine stuff.  Still a bit wony