Change map to flattenMap