Update index.js

Duplicated code removed.
Merge pull request #2 from yarikos/patch-2

Update index.js