improve readability of enforce_valid_utf8 method