Error checking to avoid 'invalid byte sequence' per #15.