refactor error handling & update test suite