Replace additional instances of map.flatten with flat_map