Refactor autocomplete example code