Refactor out pure logic in index.js