Re-added filtering function