More idiomatic code, use defaultdict