initial cleanup of the index.js
additional tidying up
fix bug, test didn't catch this though
Correcting mistake from rebase
Merge pull request #1021 from seanstrom/support/refactor-indexjs

Support/refactor indexjs