Simplify message parsing

Also adds support for multi-segment messages.