Refactored to support UTF8 invalid byte sequence scenarios