refactored new error handling