Refactor errors.
Add error-path testing.