use flat_map instead of map flatten
Merge pull request #1830 from fabiosegalla/master

#ruby's #flat_map is much faster than combining #map and #flatten.