Don't add invalid utf-8 trigram + minor code rearrange