Flatten array first before applying filter