Can we use iterator here, which might be more direct (potentially use less memory) than generating the map.