refactored helpers for multiterm search