Minor modifications to error handling.
Partially implemented unit testing.