fixing counting bug