fix buildIndices method