Reorganized error handling