fixed a bug on counting