Refactoring structure of index()