Add test and fix for duplicate keys.