fix bug with counting