Improve error handling and add failure tests.
Bump version to 0.2.2.