Optimize isTerm. Add begin and end of string anchors.