implemented Set data structure for efficiency