Refactored autocomplete stuff