Fixing a bug in CreateNamedElement

If the element didn't already exist, it would throw an error because it was using `dict[key]` instead of `dict.ContainsKey(key)`