Merge methods and remove duplicated code in AbstractMetricWriter and UniqueCountWriter