Finished script for anomaly calculation