optimize iterating a map