refactor autocomplete.js