Added sorting logic using typeahead fork