Replaced dict key guard with defaultdict.