Refactor indexing in preparation for caching.