nullcheck before flattening