Refactored index.js