Refactoring to improve efficiency/avoid defining multiple event-handlers, fixed autocompleter.js bug where multiple instances of the same command would end up sharing state