added checks to ensure no duplicate elements