Fix crashing on some cases of autocomplete