fixed autocomplete code, but still a bit buggy