added anomaly calculation code