Fixed bug with resizing buffers

When receiving a message > 8192 bytes, the buffer resizing logic was broken.