improved rebuildValueIndex.