Index: /applications/editors/josm/plugins/mapillary/build.xml
===================================================================
--- /applications/editors/josm/plugins/mapillary/build.xml	(revision 31481)
+++ /applications/editors/josm/plugins/mapillary/build.xml	(revision 31482)
@@ -5,5 +5,5 @@
     <property name="plugin.main.version" value="8433"/>
     <property name="plugin.canloadatruntime" value="true"/>
-    <property name="plugin.version" value="0.9.1"/>
+    <property name="plugin.version" value="0.9.2"/>
     <property name="plugin.author" value="nokutu &lt;nokutu@openmailbox.org&gt;"/>
     <property name="plugin.class" value="org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin"/>
Index: /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java	(revision 31481)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java	(revision 31482)
@@ -176,5 +176,4 @@
       }
       this.ex.shutdown();
-      PluginState.finishUpload();
     }
   }
Index: /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/PluginState.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/PluginState.java	(revision 31481)
+++ /applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/PluginState.java	(revision 31482)
@@ -18,5 +18,5 @@
   private static int runningDownloads = 0;
   /** Images that have to be uploaded. */
-  public static int imagesToUpload = 0;
+  protected static int imagesToUpload = 0;
   /** Images that have been uploaded. */
   public static int imagesUploaded = 0;
@@ -33,4 +33,7 @@
    */
   public static void finishDownload() {
+    if (runningDownloads == 0)
+      throw new IllegalStateException(
+          "The amount of running downlaods is less or equals to 0");
     runningDownloads--;
   }
@@ -43,14 +46,4 @@
   public static boolean isDownloading() {
     return runningDownloads > 0;
-  }
-
-  /**
-   * Called when an upload is finished.
-   */
-  public static void finishUpload() {
-    if (imagesUploaded >= imagesToUpload) {
-      imagesUploaded = 0;
-      imagesToUpload = 0;
-    }
   }
 
@@ -71,4 +64,8 @@
    */
   public static void imagesToUpload(int amount) {
+    if (imagesToUpload <= imagesUploaded) {
+      imagesToUpload = 0;
+      imagesUploaded = 0;
+    }
     imagesToUpload += amount;
   }
@@ -80,5 +77,6 @@
     imagesUploaded++;
     if (imagesToUpload == imagesUploaded) {
-      finishedUploadDialog();
+      if (Main.main != null)
+        finishedUploadDialog();
     }
   }
Index: /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecordTest.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecordTest.java	(revision 31481)
+++ /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecordTest.java	(revision 31482)
@@ -41,18 +41,21 @@
   @Test
   public void commandTest() {
-    MapillaryCommand cmd1 = new CommandMoveImage(
+    MapillaryCommand cmd12 = new CommandMoveImage(
         Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 }),
         0.1, 0.1);
-    MapillaryCommand cmd2 = new CommandMoveImage(
+    MapillaryCommand cmd23 = new CommandMoveImage(
         Arrays.asList(new MapillaryAbstractImage[] { this.img2, this.img3 }),
         0.1, 0.1);
-    MapillaryCommand cmd3 = new CommandMoveImage(
+    MapillaryCommand cmd13 = new CommandMoveImage(
         Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img3 }),
+        0.1, 0.1);
+    MapillaryCommand cmd1 = new CommandMoveImage(
+        Arrays.asList(new MapillaryAbstractImage[] { this.img1 }),
         0.1, 0.1);
     MapillaryCommand cmd31 = new CommandMoveImage(
         Arrays.asList(new MapillaryAbstractImage[] { this.img3, this.img1 }),
         0.2, 0.2);
-    this.record.addCommand(cmd1);
-    this.record.addCommand(cmd2);
+    this.record.addCommand(cmd12);
+    this.record.addCommand(cmd23);
 
     assertEquals(1, this.record.position);
@@ -64,19 +67,28 @@
     assertEquals(2, this.record.commandList.size());
 
-    this.record.addCommand(cmd3);
+    this.record.addCommand(cmd1);
 
     assertEquals(1, this.record.position);
-    assertEquals(2, this.record.commandList.size());
+
+    this.record.addCommand(cmd13);
+
+    assertEquals(2, this.record.position);
+    assertEquals(3, this.record.commandList.size());
 
     this.record.undo();
     this.record.redo();
 
-    assertEquals(1, this.record.position);
-    assertEquals(2, this.record.commandList.size());
+    assertEquals(2, this.record.position);
+    assertEquals(3, this.record.commandList.size());
 
     this.record.addCommand(cmd31);
 
-    assertEquals(1, this.record.position);
-    assertEquals(2, this.record.commandList.size());
+    assertEquals(2, this.record.position);
+    assertEquals(3, this.record.commandList.size());
+
+    this.record.addCommand(cmd1);
+
+    assertEquals(3, this.record.position);
+    assertEquals(4, this.record.commandList.size());
   }
 
Index: /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/PluginStateTest.java
===================================================================
--- /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/PluginStateTest.java	(revision 31482)
+++ /applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/PluginStateTest.java	(revision 31482)
@@ -0,0 +1,49 @@
+package org.openstreetmap.josm.plugins.mapillary.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Tests {@link PluginState} class.
+ *
+ * @author nokutu
+ * @see PluginState
+ */
+public class PluginStateTest {
+
+  /**
+   * Test the methods related to the download.
+   */
+  @Test
+  public void downloadTest() {
+    assertEquals(false, PluginState.isDownloading());
+    PluginState.startDownload();
+    assertEquals(true, PluginState.isDownloading());
+    PluginState.startDownload();
+    assertEquals(true, PluginState.isDownloading());
+    PluginState.finishDownload();
+    assertEquals(true, PluginState.isDownloading());
+    PluginState.finishDownload();
+    assertEquals(false, PluginState.isDownloading());
+  }
+
+  /**
+   * Tests the methods related to the upload.
+   */
+  @Test
+  public void uploadTest() {
+    assertEquals(false, PluginState.isUploading());
+    PluginState.imagesToUpload(2);
+    assertEquals(2, PluginState.imagesToUpload);
+    assertEquals(0, PluginState.imagesUploaded);
+    assertEquals(true, PluginState.isUploading());
+    PluginState.imageUploaded();
+    assertEquals(1, PluginState.imagesUploaded);
+    assertEquals(true, PluginState.isUploading());
+    PluginState.imageUploaded();
+    assertEquals(false, PluginState.isUploading());
+    assertEquals(0, PluginState.imagesToUpload);
+    assertEquals(0, PluginState.imagesUploaded);
+  }
+}
