Update message parsing logic and add unit tests