Filter out nil values prior to flattening in get-selected-ids