Ian: reduce duplication, check that no bytes are remaining on the input stream after reading the message