diff --git a/lib/SimpleSAML/Metadata/SAMLBuilder.php b/lib/SimpleSAML/Metadata/SAMLBuilder.php
index 2a2f447f25f3435367c5a6184c385aa8417f9a45..e5411828a3f225fc865cdb487a8aaa035b444528 100644
--- a/lib/SimpleSAML/Metadata/SAMLBuilder.php
+++ b/lib/SimpleSAML/Metadata/SAMLBuilder.php
@@ -336,19 +336,8 @@ class SimpleSAML_Metadata_SAMLBuilder {
 		
 		if (array_key_exists('contacts', $metadata) && is_array($metadata['contacts']) ) {
 			foreach($metadata['contacts'] AS $contact) {
-				if (array_key_exists('contactType', $contact) && array_key_exists('EmailAddress', $contact)) {
-					$t = $this->createElement('ContactPerson');
-					$t->setAttribute('contactType', $contact['contactType']);
-					
-					if (array_key_exists('SurName', $contact)) {
-						$surname = $this->createTextElement('SurName', $contact['SurName']);
-						$t->appendChild($surname);
-					}
-					
-					$email = $this->createTextElement('EmailAddress', $contact['EmailAddress']);
-					$t->appendChild($email);
-					
-					$this->entityDescriptor->appendChild($t);
+				if (array_key_exists('contactType', $contact) && array_key_exists('emailAddress', $contact)) {
+                    $this->addContact($contact['contactType'], $contact);
 				}
 			}
 		}
@@ -408,19 +397,8 @@ class SimpleSAML_Metadata_SAMLBuilder {
 		
 		if (array_key_exists('contacts', $metadata) && is_array($metadata['contacts']) ) {
 			foreach($metadata['contacts'] AS $contact) {
-				if (array_key_exists('contactType', $contact) && array_key_exists('EmailAddress', $contact)) {
-					$t = $this->createElement('ContactPerson');
-					$t->setAttribute('contactType', $contact['contactType']);
-					
-					if (array_key_exists('SurName', $contact)) {
-						$surname = $this->createTextElement('SurName', $contact['SurName']);
-						$t->appendChild($surname);
-					}
-					
-					$email = $this->createTextElement('EmailAddress', $contact['EmailAddress']);
-					$t->appendChild($email);
-					
-					$this->entityDescriptor->appendChild($t);
+				if (array_key_exists('contactType', $contact) && array_key_exists('emailAddress', $contact)) {
+                    $this->addContact($contact['contactType'], $contact);
 				}
 			}
 		}
@@ -672,4 +650,4 @@ class SimpleSAML_Metadata_SAMLBuilder {
 
 }
 
-?>
\ No newline at end of file
+?>