Error reporting and refactoring