convert to use Map.entrySet for efficiency
Use more efficient entrySet rather than keySet+get