Improved message parsing