refactor typeAhead util