fix counting bug