Move common typeahead code into helpers