refactor and indexing