[Shane, Soph] Refactoring and testing of autocomplete.