Check for message length. Max 512 bytes.
Correct if statements in order to conform to the standard.