Fix autocomplete and added generic hook function for mode initialization