Replaced map.flatten with flat_map
Merge pull request #3501 from strivedi183/minor_refactor

Replaced map.flatten with flat_map