Count logic