Corrected and simplified message codec.