I recently added an IterativeCreativeFilter which could greatly simplify this filter. Take a look: https://github.com/datacratic/rtbkit/blob/master/rtbkit/core/router/filters/generic_creative_filters.h#L70

Note that I haven't really tested it yet so there might be a bug or two in there.