Make autocomplete function more idiomatic.