Add some tests and fix cases when not all the message is received at once