diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js
index be925af19b..7c1c5b34d7 100644
--- a/src/MatrixClientPeg.js
+++ b/src/MatrixClientPeg.js
@@ -97,35 +97,20 @@ class MatrixClient {
 
     // FIXME, XXX: this all seems very convoluted :(
     //
-    // if we replace the singleton using URLs we bypass our createClientForPeg()
-    // global helper function... but if we replace it using
-    // an access_token we don't?
-    //
     // Why do we have this peg wrapper rather than just MatrixClient.get()?
     // Why do we name MatrixClient as MatrixClientPeg when we export it?
     //
     // -matthew
 
     replaceUsingUrls(hs_url, is_url) {
-        matrixClient = Matrix.createClient({
-            baseUrl: hs_url,
-            idBaseUrl: is_url
-        });
-
-        // XXX: factor this out with the localStorage setting in replaceUsingAccessToken
-        if (localStorage) {
-            try {
-                localStorage.setItem("mx_hs_url", hs_url);
-                localStorage.setItem("mx_is_url", is_url);
-            } catch (e) {
-                console.warn("Error using local storage: can't persist HS/IS URLs!");
-            }
-        } else {
-            console.warn("No local storage available: can't persist HS/IS URLs!");
-        }
+        this.replaceClient(hs_url, is_url);
     }
 
     replaceUsingAccessToken(hs_url, is_url, user_id, access_token, isGuest) {
+        this.replaceClient(hs_url, is_url, user_id, access_token, isGuest);
+    }
+
+    replaceClient(hs_url, is_url, user_id, access_token, isGuest) {
         if (localStorage) {
             try {
                 localStorage.clear();