Better handling of non-mandatory elements in filtering code

We should not compare None with non-none values -- we need to handle
it specially.

Change-Id: I25b5ef7ac0595e21f33081f106968c047fdaebfe