state machine: improve input to be safer