Optimize replaceSpecialIdentifiers