Updated asDictionary to work with all collections.