move typeahead logic into main.js