Reduced duplicate code in index.js