refactor - error handling