Fixed filtering function