handle duplicate keys

Handle duplicate keys correctly, e.g. the same way that the request module does it (should fix #1)