Added rebuildIndices function