Fix for textbox autocomplete and some refactoring