diff --git a/appinfo/routes.php b/appinfo/routes.php
index 8c4874d92ece37e3c25802f4a457280f0d1ad453..334729d122f4ddcad0eaeb7e07e19b3a697522c6 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -10,6 +10,10 @@
 return [
 	'routes' => [
 		['name' => 'SecondaryMail#setProperty', 'url' => '/settings', 'verb' => 'POST'],
+	],
+	
+	'ocs' => [
 		['name' => 'SecondaryMail#getAddress', 'url' => '/getAddress/{id}', 'verb' => 'GET'],
+		['name' => 'SecondaryMail#setProperty', 'url' => '/settings', 'verb' => 'POST'],
 	]
 ];
diff --git a/composer.json b/composer.json
index ba0e1e14a0992b6c53a1d84466daeaa46f5f5304..5d8d42f81237db8427c1208ef2aff3ce6ab60db5 100644
--- a/composer.json
+++ b/composer.json
@@ -1,5 +1,5 @@
 {
-    "name": "OpenTools/Secondary_Mail",
+    "name": "opentools/secondary_mail",
     "description": "Enter a secondary email and specify which e-Mail should be used for external communication",
     "type": "project",
     "license": "AGPL",
diff --git a/js/script.js b/js/script.js
index cd37a583e5ad97f1d7c06c8181d62c0cdbd72ebb..7ea46c3e08e5a14d12d3935ecb62c40779d78634 100644
--- a/js/script.js
+++ b/js/script.js
@@ -20,6 +20,27 @@
 
 'use strict';
 
+(function(OCA) {
+	/**
+	 * @namespace OCA.Secondary_Mail
+	 */
+	OCA.Secondary_Mail = {
+		_submitChange: function(target) {
+			if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
+				OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(this._submitChange, this, target));
+				return;
+			}
+			var url = OC.generateUrl('/apps/secondarymail/settings');
+			let key = target.data('setting'),
+				value = target.val();
+			if (target.attr('type') === 'checkbox') {
+				value = target[0].checked ? 'true' : 'false';
+			}
+			$.post(url, {key, value});
+			return true;
+		}
+	}
+})(OCA);
 
 (function () {
 	function initialize() {
@@ -33,6 +54,14 @@
 	}
 	
 	function _submitChange(e) {
+		return OCA.Secondary_Mail._submitChange($(e.target));
+	}
+
+	function _submitChangeOLD(e) {
+		if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
+			OC.PasswordConfirmation.requirePasswordConfirmation(_.bind(_submitChange, e));
+			return;
+		}
 		var url = OC.generateUrl('/apps/secondarymail/settings');
 		let target = $(e.target),
 			key = target.data('setting'),
@@ -47,3 +76,4 @@
 	initialize();
 })();
 
+
diff --git a/lib/Controller/SecondaryMailController.php b/lib/Controller/SecondaryMailController.php
index 66af624a600c250b181381c083aac332e4ba0f3f..88f7e9de469ae75bfe7d4eca0490852bf2c5e4a7 100644
--- a/lib/Controller/SecondaryMailController.php
+++ b/lib/Controller/SecondaryMailController.php
@@ -46,7 +46,6 @@ class SecondaryMailController extends OCSController {
 		$this->config = $config;
 		$this->userManager = $userManager;
 		$this->user = $userSession->getUser()->getUID();
-error_log('MailsSecondaryController::_construct');
 	}
 
 	/**
@@ -55,7 +54,7 @@ error_log('MailsSecondaryController::_construct');
 	 */
 	public function setProperty($key, $value) {
 		if (in_array($key, array('emailUsePrimary', 'emailUseSecondary', 'email2'))) {
-			if ($key === 'email2' && $value == "") {
+			if ($key === 'email2' && $value === "") {
 				$this->config->deleteUserValue($this->user, 'settings', $key);
 			} else {
 				$this->config->setUserValue($this->user, 'settings', $key, $value);
@@ -70,18 +69,28 @@ error_log('MailsSecondaryController::_construct');
 	 */
 	public function getAddress($id) {
 		$mails = array();
+		$data = array();
 		
-		if ($this->config->getUserValue($id, 'settings', 'emailUsePrimary')) {
+		$usePrimary = $this->config->getUserValue($id, 'settings', 'emailUsePrimary', 'true');
+		$data['usePrimary'] = $usePrimary;
+		if ($usePrimary === 'true' || $usePrimary === 1 || $usePrimary === "Y") {
 			$user = $this->userManager->get($id);
 			$email = $user->getEMailAddress();
-			if (!is_empty($email)) {
+			if (!empty($email)) {
 				$mails[] = $user->getEMailAddress();
 			}
 		}
-		if ($this->config->getUserValue($id, 'settings', 'emailUseSecondary')) {
-			$mails[] = $this->config->getUserValue($id, 'settings', 'email2');
+		
+		$useSecondary = $this->config->getUserValue($id, 'settings', 'emailUseSecondary', 'true');
+		$data['useSecondary'] = $useSecondary;
+		if ($useSecondary === 'true' || $useSecondary === 1 || $useSecondary === "Y") {
+			$secondary = $this->config->getUserValue($id, 'settings', 'email2');
+			if (!empty($secondary)) {
+				$mails[] = $secondary;
+			}
 		}
-		return join(',',$mails);
+		$data['email'] = $mails;
+		return new DataResponse($data);
 	}
 
 }