Better use of key iterator

This commit uses an EntrySet instead of looping over the keys and
retrieving the value in a separate call.

Issue: SPR-12356
Merge pull request #667 from luckybomb/spr12356

* spr12356:
  Better use of key iterator