- Refactor error handling