fix autocomplete bug and add guard