refactoring index.js