Refactored error parsing