logging; counting fixes; use sets