refactoring of autocomplete