Error handling and supporting unit tests.
Not at 100% coverage yet.