Minor improvement: could iterate over the entrySet to avoid repeated gets