Fix infinite loop in autocompletion