fix counter logic