refactored error handling (no change yet)