A lot of the above logic is identical to that of `-initWithDictionary:error:`. Can you factor it out into a method or static function?