Handle duplicate keys better