diff --git a/javascript/src/Identity.js b/javascript/src/Identity.js
index 43a52eafc057f67cf2feb961db87e5392f015f4d..22b112ca9e833dd25ce67e38def5a22cf32bd2ef 100644
--- a/javascript/src/Identity.js
+++ b/javascript/src/Identity.js
@@ -1,51 +1,39 @@
-function Identity() {
-}
-
-Identity.prototype.set = function(obj) {
-  for(var member in obj) {
-    this[member] = JSON.parse(JSON.stringify(obj[member]))
+class Identity {
+  constructor(source) {
+    let identityData = {};
+
+    if (typeof source === "string") {
+      try {
+        identityData = JSON.parse(source);
+      } catch (e) {
+        console.warn(e);
+      }
+    } else if (typeof source === "object") {
+      identityData = source;
+    }
+
+    const { authentication, pinCode, passports } = identityData;
+
+    this.authentication = authentication;
+    this.pinCode = pinCode;
+    this.passports = passports || {};
   }
-};
-
-Identity.prototype.serialize = function() {
-  return JSON.stringify(this)
-};
-
-Identity.prototype.deserialize = function(serialized) {
-  var obj = JSON.parse(serialized);
-  this.set(obj)
-};
-
-Identity.prototype.setAuthentication = function(cryptoData) {
-  this["authentication"] = cryptoData
-};
-
-Identity.prototype.getAuthentication = function() {
-  return this["authentication"]
-};
 
-Identity.prototype.setPinCode = function(pinCode) {
-  this["pinCode"] = pinCode
-};
-
-Identity.prototype.getPinCode = function() {
-  return this["pinCode"]
-};
-
-Identity.prototype.setPassport = function(passportUUID, cryptoData) {
-  if(this["passports"] === undefined || this["passports"] === null) {
-    this["passports"] = {}
+  setAuthentication(cryptoData) {
+    this.authentication = cryptoData;
   }
 
-  this["passports"][passportUUID] = cryptoData
-};
+  setPinCode(pinCode) {
+    this.pinCode = pinCode;
+  }
 
-Identity.prototype.getPassport = function(passportUUID) {
-  if(this["passports"] === undefined || this["passports"] === null) {
-    this["passports"] = {}
+  setPassport(passportUUID, cryptoData) {
+    this.passports[passportUUID] = cryptoData;
   }
 
-  return this["passports"][passportUUID]
-};
+  getPassport(passportUUID) {
+    return this.passports[passportUUID];
+  }
+}
 
-export default Identity;
\ No newline at end of file
+export default Identity;
diff --git a/javascript/src/iframe/viamapi-iframe.js b/javascript/src/iframe/viamapi-iframe.js
index aca2eb9ebeff17653fd1dd45afd1d0368b9d0d7c..928b4fe78e2b5181ad2d88d87a70f9643a27e3af 100644
--- a/javascript/src/iframe/viamapi-iframe.js
+++ b/javascript/src/iframe/viamapi-iframe.js
@@ -116,32 +116,28 @@ function getProfileData(identity) {
   });
 }
 
-function getIdentityFromLocalStorage(key, pinCode, extendTtl = true) {
+async function getIdentityFromLocalStorage(key, pinCode, extendTtl = true) {
   const encryptedIdentity = localStorage.getItem(key);
-  if (encryptedIdentity == null) {
+
+  if (!encryptedIdentity) {
     console.log("No such identity for public key");
-    return Promise.resolve(null)
+    return null;
   }
-  return decryptMessage(encryptedIdentity, pinCode).then((serializedIdentity) => {
-    var parsedIdentity = JSON.parse(serializedIdentity);
-    parsedIdentity["pinCode"] = "";
-
-    if(extendTtl === true) {
-      var success = extendPinCodeTtl(key, pinCode);
-      if (success === true) {
-        return parsedIdentity
-      } else {
-        console.log("Can not extend pincode ttl");
-        return null
-      }
-    } else {
-      return parsedIdentity
-    }
-  });
 
-}
+  const serializedIdentity = await decryptMessage(encryptedIdentity, pinCode);
 
+  const identity = new Identity(serializedIdentity);
 
+  if (extendTtl) {
+    const success = extendPinCodeTtl(key, pinCode);
+    if (!success) {
+      console.log("Can not extend pincode ttl");
+      return null;
+    }
+  }
+
+  return identity;
+}
 
 function extendPinCodeTtl(key, pinCode) {
   if(pinCode == null || pinCode === "") {
@@ -260,11 +256,12 @@ function loadIdentityInternal(identityKey, pinCode) {
         });
       }
       localStorage.removeItem("attempt");
-      const copiedIdentity = JSON.parse(JSON.stringify(loadedIdentity));
+
       window.loadedIdentities[identityKey] = loadedIdentity;
+      window.currentlyLoadedIdentity = loadedIdentity;
 
       if (identityKey === localStorage.getItem("authenticatedIdentity")) {
-        window.currentlyAuthenticatedIdentity = copiedIdentity;
+        window.currentlyAuthenticatedIdentity = loadedIdentity;
         const uuid = localStorage.getItem("uuid");
         const token = localStorage.getItem("token");
         const deviceHash = await createDeviceHash(identityKey);
@@ -273,14 +270,17 @@ function loadIdentityInternal(identityKey, pinCode) {
         window.viamApi.setSessionData(uuid, token);
       }
 
-      window.currentlyLoadedIdentity = copiedIdentity;
       window.viamAnonymousApi.setIdentity(window.currentlyLoadedIdentity.authentication.publicKey);
 
-      copiedIdentity.pinCode = "";
-      copiedIdentity.authentication.privateKey = "";
+      const { publicKey, x509Certificate } = loadedIdentity.authentication;
 
       result({
-        "data": copiedIdentity,
+        "data": {
+          authentication: {
+            publicKey,
+            x509Certificate
+          }
+        },
         "code": "200",
         "status": "Identity loaded"
       });
@@ -334,15 +334,7 @@ function getCertificateForPassport(passportUUID, internal) {
       }
     }
 
-    let passportIdentity;
-
-    if (window.currentlyAuthenticatedIdentity instanceof Identity) {
-      passportIdentity = window.currentlyAuthenticatedIdentity;
-    } else {
-      passportIdentity = new Identity();
-      passportIdentity.set(window.currentlyAuthenticatedIdentity);
-    }
-
+    const passportIdentity = window.currentlyAuthenticatedIdentity;
     var passport = passportIdentity.getPassport(passportUUID);
     if(passport === undefined || passport === null) {
       createPassportCertificate(passportUUID).then(function(keys){