refactoring dynamic index generation