extract util code
add message class
remove unused encode method
add messages constants and static initializer
die on any non zero value
handle multiple messages in receive buffer
move Messages to separate .cpp file
more misc changes to main (i should really add some tests)