Index: /applications/editors/josm/plugins/imagerycache/src/org/openstreetmap/josm/plugins/imagerycache/TileDAOMapDB.java
===================================================================
--- /applications/editors/josm/plugins/imagerycache/src/org/openstreetmap/josm/plugins/imagerycache/TileDAOMapDB.java	(revision 29945)
+++ /applications/editors/josm/plugins/imagerycache/src/org/openstreetmap/josm/plugins/imagerycache/TileDAOMapDB.java	(revision 29946)
@@ -69,7 +69,7 @@
                 storages.put(source, m);
                 
-                System.out.println("Opened database file successfully: "+f.getAbsolutePath());
+                Main.info("Opened database file successfully: "+f.getAbsolutePath());
             } catch (Exception ex) {
-                System.out.println("Error: can not create database, file: "+f.getAbsolutePath());
+                Main.warn("Error: can not create database, file: "+f.getAbsolutePath());
                 //System.out.println(ex.getMessage());
                 ex.printStackTrace();
@@ -171,5 +171,5 @@
                 
                 // Merging!
-                System.out.println("Moving records from "+f.getName()+" to open storage "+source);
+                Main.info("Moving records from "+f.getName()+" to open storage "+source);
                 myMap.putAll(m);
                 db.close();
@@ -177,5 +177,5 @@
                 f.delete();
                 
-                System.out.println("Moved database successfully from file "+f.getAbsolutePath());
+                Main.info("Moved database successfully from file "+f.getAbsolutePath());
             } catch (Exception ex) {
                 System.out.println(ex.getMessage());
@@ -192,19 +192,24 @@
         try {
             dbs.get(name).close();
-            dbs.remove(name);
-            storages.remove(name);
-            for (int t=0; t<20; t++) {
-                String fname = getDBFileName(name, t);
-                File f = new File(cacheFolder, fname);
-                if (!f.exists() || !f.canWrite()) continue;
+        } catch (Exception e) {
+            Main.warn("Something may be wrong, can not close the database.");
+        }
+
+        dbs.remove(name);
+        storages.remove(name);
+        for (int t=0; t<20; t++) {
+            String fname = getDBFileName(name, t);
+            File f = new File(cacheFolder, fname);
+            if (!f.exists() || !f.canWrite()) continue;
+            f.delete();
+            f = new File(cacheFolder, fname+".p");
+            if (!f.exists() || !f.canWrite()) continue;
+            f.delete();
+            f = new File(cacheFolder, fname+".lock");
+            if (!f.exists() || !f.canWrite()) continue;
+            try {
                 f.delete();
-                f = new File(cacheFolder, fname+".p");
-                if (!f.exists() || !f.canWrite()) continue;
-                f.delete();
-                f = new File(cacheFolder, fname+".lock");
-                if (!f.exists() || !f.canWrite()) continue;
-                f.delete();
-            }
-        } catch (Exception e) { Main.warn("Can not delete file, maybe it is locvked by another JOSM instance. This is not a serious error then."); }
+            } catch (Exception e) { Main.warn("Can not delete file, maybe it is locvked by another JOSM instance. This is not a serious error then."); }
+        }
     }
 }
