Performance fix for dictionary keys when key is not a string