Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java	(revision 31806)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java	(revision 31807)
@@ -9,4 +9,5 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
+import org.openstreetmap.josm.plugins.mapillary.io.download.MapillaryDownloader;
 
 /**
@@ -24,23 +25,25 @@
   public static boolean isTokenValid = true;
 
+  private MapillaryUser() {
+    // Private constructor to avoid instantiation
+  }
+
   /**
-   * Returns the username of the logged user.
-   *
    * @return The username of the logged in user.
    */
   public static String getUsername() {
-    if (!isTokenValid)
+    if (!isTokenValid) {
       return null;
-    if (username == null)
+    }
+    if (username == null) {
       try {
         username = OAuthUtils
-            .getWithHeader(
-                new URL(
-                    "https://a.mapillary.com/v2/me?client_id="+MapillaryPlugin.CLIENT_ID))
+            .getWithHeader(new URL(MapillaryDownloader.BASE_URL+"me?client_id="+MapillaryPlugin.CLIENT_ID))
             .getString("username");
       } catch (IOException e) {
-        Main.info("Invalid Mapillary token, reseting field");
+        Main.info("Invalid Mapillary token, resetting field");
         reset();
       }
+    }
     return username;
   }
Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java	(revision 31806)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java	(revision 31807)
@@ -1,6 +1,4 @@
 // License: GPL. For details, see LICENSE file.
 package org.openstreetmap.josm.plugins.mapillary.oauth;
-
-import static org.openstreetmap.josm.tools.I18n.tr;
 
 import java.io.IOException;
@@ -14,4 +12,5 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.tools.I18n;
 
 /**
@@ -23,11 +22,17 @@
  */
 public class OAuthPortListener extends Thread {
+  public static final int PORT = 8763;
 
-  protected static final String RESPONSE = tr("<html><head><title>Mapillary login</title></head><body>Login successful, return to JOSM.</body></html>");
+  protected static final String RESPONSE = String.format(
+      "<!DOCTYPE html><html><head><meta charset=\"utf8\"><title>%s</title></head><body>%s</body></html>",
+      I18n.tr("Mapillary login"),
+      I18n.tr("Login successful, return to JOSM.")
+  );
+
 
   @Override
   public void run() {
     try {
-      ServerSocket serverSocket = new ServerSocket(8763);
+      ServerSocket serverSocket = new ServerSocket(PORT);
       Socket clientSocket = serverSocket.accept();
       PrintWriter out = new PrintWriter(new OutputStreamWriter(
@@ -37,18 +42,17 @@
       String s;
       String accessToken = null;
-      while (in.hasNextLine()) {
+      while (in.hasNextLine() && accessToken == null) {
         s = in.nextLine();
         if (s.contains("access_token=")) {
           String[] ss = s.split("&");
-          for (int i = 0; i < ss.length; i++) {
-            if (ss[i].contains("access_token=")) {
-              accessToken = ss[i].substring(
-                  ss[i].indexOf("access_token=") + 13, ss[i].length());
-              break;
+          for (int i = 0; i < ss.length && accessToken == null; i++) {
+            if (ss[i].startsWith("access_token=")) {
+              accessToken = ss[i].substring(ss[i].indexOf("access_token=") + 13, ss[i].length());
             }
           }
           break;
-        } else if (s.contains("keep-alive"))
+        } else if (s.contains("keep-alive")) {
           break;
+        }
       }
 
@@ -61,6 +65,5 @@
       MapillaryUser.reset();
 
-      Main.info("Successful login with Mapillary, the access token is: "
-          + accessToken);
+      Main.info("Successful login with Mapillary, the access token is: " + accessToken);
       // Saves the access token in preferences.
       MapillaryUser.isTokenValid = true;
@@ -70,4 +73,5 @@
       }
     } catch (BindException e) {
+      Main.warn(e);
       return;
     } catch (IOException e) {
Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java	(revision 31806)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java	(revision 31807)
@@ -34,6 +34,5 @@
     HttpURLConnection con = (HttpURLConnection) url.openConnection();
     con.setRequestMethod("GET");
-    con.setRequestProperty("Authorization",
-        "Bearer " + Main.pref.get("mapillary.access-token"));
+    con.setRequestProperty("Authorization", "Bearer " + Main.pref.get("mapillary.access-token"));
 
     try (
Index: applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListenerTest.java
===================================================================
--- applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListenerTest.java	(revision 31806)
+++ applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListenerTest.java	(revision 31807)
@@ -34,5 +34,5 @@
     }
     try {
-      URL url = new URL("http://localhost:8763?access_token=access_token");
+      URL url = new URL("http://localhost:"+OAuthPortListener.PORT+"?access_token=access_token");
       HttpURLConnection con = (HttpURLConnection) url.openConnection();
       BufferedReader in = new BufferedReader(new InputStreamReader(
