refactoring the index engine