Improved state machine parser.