[fix] fix for receiving packet where the size has been encoded the way

that the last byte layed at the end of the current buffer
[fix] fix for receiving packets that has empty data chunk
[tidy] removed unneded debug code
[tidy] moved error reporting to improve debug logging