More efficient use of map iterator.
Moving utility methods around to avoid package cycles.