Ensured no duplicates. Fixed loop in JS