Improved code to select the best index to use when matching a quad pattern based on which terms are bound.