This whole block:

```javascript
if ( metadata ) {
    result[ "metadata" ] = metadata;
} else {
    result[ "metadata" ] = {};
}
```

can be refactored to

```javascript
result[ "metadata" ] = metadata || {};
```

From [Crockford]():

> The || operator is commonly called logical or. It can also be called default. If the first operand is false, null, undefined, "" (the empty string), or the number 0, then it returns the second operand. Otherwise, it returns the first operand. This provides a convenient way to specify default values:
>
>     value = v || 10; /* Use the value of v, but if v
>     doesn't have a value, use 10 instead. */