added handling of duplicates