improved validation and truncation of utf8.