handle duplicates, make js work in Chrome and IE