Refactoring index.js