Lots of refactoring / renaming. Added integration tests for index.js.