Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java	(revision 31986)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java	(revision 31987)
@@ -375,11 +375,11 @@
   }
 
-  private void fireSelectedImageChanged(MapillaryAbstractImage oldImage,
-                                        MapillaryAbstractImage newImage) {
+  private void fireSelectedImageChanged(MapillaryAbstractImage oldImage, MapillaryAbstractImage newImage) {
     if (this.listeners.isEmpty())
       return;
-    for (MapillaryDataListener lis : this.listeners)
+    for (MapillaryDataListener lis : this.listeners) {
       if (lis != null)
         lis.selectedImageChanged(oldImage, newImage);
+    }
   }
 
Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java	(revision 31986)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java	(revision 31987)
@@ -91,9 +91,9 @@
     } else if (this.dialog.group.isSelected(this.dialog.rewrite.getModel())) {
       ArrayList<MapillaryImportedImage> images = new ArrayList<>();
-      for (MapillaryAbstractImage image : MapillaryLayer.getInstance()
-          .getData().getImages())
+      for (MapillaryAbstractImage image : MapillaryLayer.getInstance().getData().getImages()) {
         if (image instanceof MapillaryImportedImage) {
           images.add((MapillaryImportedImage) image);
         }
+      }
       try {
         Main.worker.submit(new Thread(new MapillaryExportManager(images)));
Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java	(revision 31986)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java	(revision 31987)
@@ -58,22 +58,11 @@
       while (!this.end && this.data.getSelectedImage().next() != null) {
         MapillaryAbstractImage image = this.data.getSelectedImage();
-        if (image instanceof MapillaryImage) {
+        if (image != null && image.next() instanceof MapillaryImage) {
           // Predownload next 10 thumbnails.
-          for (int i = 0; i < 10; i++) {
-            if (image.next() == null) {
-              break;
-            }
-            image = image.next();
-            CacheUtils.downloadPicture((MapillaryImage) image, CacheUtils.PICTURE.THUMBNAIL);
+          preDownloadImages((MapillaryImage) image.next(), 10, CacheUtils.PICTURE.THUMBNAIL);
+          if (this.waitForFullQuality) {
+            // Start downloading 3 next full images.
+            preDownloadImages((MapillaryImage) image.next(), 3, CacheUtils.PICTURE.FULL_IMAGE);
           }
-          if (this.waitForFullQuality)
-            // Start downloading 3 next full images.
-            for (int i = 0; i < 3; i++) {
-              if (image.next() == null) {
-                break;
-              }
-              image = image.next();
-              CacheUtils.downloadPicture((MapillaryImage) image, CacheUtils.PICTURE.FULL_IMAGE);
-            }
         }
         try {
@@ -117,4 +106,19 @@
     }
     end();
+  }
+
+  /**
+   * Downloads n images into the cache beginning from the supplied start-image (including the start-image itself).
+   * @param startImage the image to start with (this and the next n-1 images in the same sequence are downloaded)
+   * @param n the number of images to download
+   * @param type the quality of the image (full or thumbnail)
+   */
+  private void preDownloadImages(MapillaryImage startImage, int n, CacheUtils.PICTURE type) {
+    if (n >= 1 && startImage != null) {
+      CacheUtils.downloadPicture(startImage, type);
+      if (startImage.next() instanceof MapillaryImage && n >= 2) {
+        preDownloadImages((MapillaryImage) startImage.next(), n - 1, type);
+      }
+    }
   }
 
Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java	(revision 31986)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java	(revision 31987)
@@ -122,7 +122,8 @@
 
   private void fireRecordChanged() {
-    for (MapillaryRecordListener lis : this.listeners)
+    for (MapillaryRecordListener lis : this.listeners) {
       if (lis != null)
         lis.recordChanged();
+    }
   }
 
Index: applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryDownloader.java
===================================================================
--- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryDownloader.java	(revision 31986)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryDownloader.java	(revision 31987)
@@ -26,5 +26,5 @@
  *
  */
-public class MapillaryDownloader {
+public final class MapillaryDownloader {
 
   /** Possible download modes. */
@@ -39,4 +39,8 @@
   /** Executor that will run the petitions. */
   private static ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100));
+
+  private MapillaryDownloader() {
+    // Private constructor to avoid instantiation
+  }
 
   /**
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 31986)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java	(revision 31987)
@@ -19,5 +19,9 @@
  *
  */
-public class OAuthUtils {
+public final class OAuthUtils {
+
+  private OAuthUtils() {
+    // Private constructor to avoid instantiation
+  }
 
   /**
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 31986)
+++ applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java	(revision 31987)
@@ -33,6 +33,5 @@
 import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet;
 import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.ContentType;
@@ -260,11 +259,11 @@
       HttpEntity entity = entityBuilder.build();
       httpPost.setEntity(entity);
-      HttpResponse response = httpClient.execute(httpPost);
-
-      if (response.getStatusLine().toString().contains("204")) {
-        PluginState.imageUploaded();
-        Main.info(PluginState.getUploadString() + " (Mapillary)");
-      } else {
-        Main.info("Upload error");
+      try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
+        if (response.getStatusLine().toString().contains("204")) {
+          PluginState.imageUploaded();
+          Main.info(PluginState.getUploadString() + " (Mapillary)");
+        } else {
+          Main.info("Upload error");
+        }
       }
     }
