optimizing terms lookup