Re-merged error handling enhancements with most recent code