diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl
index 93d1acdee..4c03926d7 100644
--- a/config/cfgroot/ids-functions.pl
+++ b/config/cfgroot/ids-functions.pl
@@ -1086,11 +1086,8 @@ sub _cleanup_rulesdir() {
 		# We only want files.
 		next unless (-f "$rulespath/$file");
 
-		# Skip rules file for whitelisted hosts.
-		next if ("$rulespath/$file" eq $whitelist_file);
-
-		# Skip rules file with local rules.
-		next if ("$rulespath/$file" eq $local_rules_file);
+		# Skip any files which are part of the array of statically included rulefiles.
+		next if (grep(/$file/, @static_included_rulefiles));
 
 		# Delete the current processed file, if not, exit this function
 		# and return an error message.
