diff --git a/lib/SimpleSAML/Metadata/SAMLBuilder.php b/lib/SimpleSAML/Metadata/SAMLBuilder.php
index 87702af25d830e01d193c4ae0c475562c7af03f6..a8f26191eaee854c19d3086ec2b9a91309ed6a28 100644
--- a/lib/SimpleSAML/Metadata/SAMLBuilder.php
+++ b/lib/SimpleSAML/Metadata/SAMLBuilder.php
@@ -287,7 +287,7 @@ class SimpleSAML_Metadata_SAMLBuilder {
 		}
 
 
-		if ( array_key_exists('name', $metadata) || array_key_exists('attributes', $metadata)) {
+		if ( array_key_exists('name', $metadata) && array_key_exists('attributes', $metadata)) {
 			/**
 			 * Add an AttributeConsumingService element with information as name and description and list
 			 * of requested attributes
diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php
index 80f88b9a728368dcb27ee9214b4ceaed98056869..73510ae24d6eed83439d0712726f95d0e6801698 100644
--- a/lib/SimpleSAML/Metadata/SAMLParser.php
+++ b/lib/SimpleSAML/Metadata/SAMLParser.php
@@ -481,6 +481,7 @@ class SimpleSAML_Metadata_SAMLParser {
 		if($acs === NULL) {
 			SimpleSAML_Logger::warning('Could not find a supported SAML 1.x AssertionConsumerService endpoint for ' .
 				var_export($ret['entityid'], TRUE) . '.');
+			return;
 		} else {
 			$ret['AssertionConsumerService'] = $acs['Location'];
 		}
@@ -506,7 +507,6 @@ class SimpleSAML_Metadata_SAMLParser {
 			break;
 		}
 
-
 		return $ret;
 	}
 
@@ -548,6 +548,7 @@ class SimpleSAML_Metadata_SAMLParser {
 		if($sso === NULL) {
 			SimpleSAML_Logger::warning('Could not find a supported SAML 1.x SingleSignOnService endpoint for ' .
 				var_export($ret['entityid'], TRUE) . '.');
+			return;
 		} else {
 			$ret['SingleSignOnService'] = $sso['Location'];
 		}
@@ -877,8 +878,7 @@ class SimpleSAML_Metadata_SAMLParser {
 		$attcs = SimpleSAML_Utilities::getDOMChildren($element, 'AttributeConsumingService', '@md');
 		if (count($attcs) > 0) {
 			self::parseAttributeConsumerService($attcs[0], $sp);
-		}
-		
+		}	
 
 		$this->spDescriptors[] = $sp;
 	}