Implement a function factory for the typeahead callbacks

- Remove repeating code