refactor error handling of #8