Clean up state machine style a bit