changed message parsing and unparsing to be correct