added check to isUTF8Valid to detect end of string during continuation bytes