Fixed some logic errors in the message parser