Update index.js to be more complete, adding comments and examples.

Adding more detail via comments, testability improvements, etc.