what seems to be a working version of a state machine for option parsing