Refactor index.js