refactored error extraction