Refactoring error handling.