Improve function for turning KeyValues into Python dictionaries.