More sophisticated FSM implementation to parse strings of fixed format