Error handling refactoring.