flatten and flattenExt