Improved and streamlines the code of the autocomplete.