Added exception handling to detect_cluster