Further simplify, use sets to prevent duplicating keys