Use flat_map instead of map.flatten

Should be a bit faster, less allocations.  Not sure if I should be doing this on stable or master..