Redesigned message handling

Also fixed buffer overflow security vulnerability in message receiving
code