sorting autocomplete results and some cleanup