refactor index.js; replace switch with functions in an object literal