Improved typeahead logic