Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java	(revision 31975)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java	(revision 31976)
@@ -2,4 +2,5 @@
 package org.openstreetmap.josm.plugins.mapillary;
 
+import java.awt.Image;
 import java.io.IOException;
 
@@ -48,4 +49,6 @@
   /** 16x16 icon. */
   public static final ImageIcon ICON16 = new ImageProvider("icon16.png").get();
+  /** 12x12 icon. */
+  public static final ImageIcon ICON12 = new ImageIcon(ICON24.getImage().getScaledInstance(12, 12, Image.SCALE_SMOOTH));
   /** Icon representing an image in the map. */
   public static final ImageIcon MAP_ICON = new ImageProvider("mapicon.png").get();
Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java	(revision 31975)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java	(revision 31976)
@@ -74,7 +74,8 @@
     panel.add(this.reverseButtons, GBC.eol());
     // Sets the value of the ComboBox.
-    if (Main.pref.get("mapillary.download-mode").equals(MapillaryDownloader.MODES.Automatic.toString())
-        || Main.pref.get("mapillary.download-mode").equals(MapillaryDownloader.MODES.Semiautomatic.toString())
-        || Main.pref.get("mapillary.download-mode").equals(MapillaryDownloader.MODES.Manual.toString())) {
+    String downloadMode = Main.pref.get("mapillary.download-mode");
+    if (MapillaryDownloader.MODES.Automatic.toString().equals(downloadMode)
+        || MapillaryDownloader.MODES.Semiautomatic.toString().equals(downloadMode)
+        || MapillaryDownloader.MODES.Manual.toString().equals(downloadMode)) {
       this.downloadMode.setSelectedItem(Main.pref.get("mapillary.download-mode"));
     }
@@ -94,5 +95,8 @@
     panel.add(Box.createVerticalGlue(), GBC.eol().fill(GridBagConstraints.BOTH));
 
-    gui.getDisplayPreference().addSubTab(this, "Mapillary", new JScrollPane(panel));
+    synchronized (gui.getDisplayPreference().getTabPane()) {
+      gui.getDisplayPreference().addSubTab(this, "Mapillary", new JScrollPane(panel));
+      gui.getDisplayPreference().getTabPane().setIconAt(gui.getDisplayPreference().getTabPane().getTabCount()-1, MapillaryPlugin.ICON12);
+    }
 
     new Thread(new Runnable() {
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 31975)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java	(revision 31976)
@@ -10,4 +10,6 @@
 import java.net.Socket;
 import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.openstreetmap.josm.Main;
@@ -47,11 +49,7 @@
       while (in.hasNextLine() && accessToken == null) {
         s = in.nextLine();
-        if (s.contains("access_token=")) {
-          String[] ss = s.split("&");
-          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());
-            }
-          }
+        Matcher tokenMatcher = Pattern.compile("^.*&access_token=([^&]+)&.*$").matcher('&'+s+'&');
+        if (tokenMatcher.matches()) {
+          accessToken = tokenMatcher.group(1);
           break;
         } else if (s.contains("keep-alive")) {
@@ -61,8 +59,5 @@
 
       writeContent(out);
-
-      out.close();
-      in.close();
-      serverSocket.close();
+      out.flush();
 
       MapillaryUser.reset();
