Automated Aggregator -- Rewriting with the Counting Aggregate