Refactor code. Use defaultdict(list)