Refactor indexing