Fix for bug #1: Better resizing of read buffer. Also included more robust message parsing.