fix counting functions