used defaultdict where apporpriate