Bunch of code refactoring and cleaning up auto complete functionality