Rewrote serialization of messages.
Closes #27