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