Verify that the dictionary exists before assigning a value.

Fixes #991