Refactored autocomplete, code cleanup, bug fixes