would it make more sense to change this to a defaultdict?