Use sets instead of arrays where appropriate