added checking for duplicates