added error handling and check for duplicates