Refactor of index.js.