DEMO-4 Added a check for duplicates in the JS file and did some refactoring