Shouldn't this be:

`````
result[key] += val;
`````

??