Refactor autocomplete