use entrySet instead of Keyset to improve performance.