Refactoring: error message handling