Refactored check for 401 errors in core methods.