Counter logic