Changing parser to use a state machine