Replace defaultdict with OrderedDefaultDict