Rewrote sending code to send entire message as a single block of bytes

This helps to avoid reordering of the message length and message contents