would using exceptions to encapsulate this logic make more sense? seems like all these error conditions could be replaced with `raise SMSParseError(msg)` and a handler outside the loop.