Refactoring some common code in clusters and anomalies