Simplify by switching to a set-based implementation