Anomaly detector: added a safety check