Properly compare occurrences in filter