Added optimization to GetLocationCount.