Use `domain' for error handling

Error handling has been improved here.  A bunch of minor problems that
slipped by before have been addressed as well.
Refactor index.js

It has been split into several smaller modules.
Bump version to 0.6.1