fixes bug with click selecting autocomplete and simplifies code.