Index: trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java	(revision 11250)
+++ trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java	(revision 11252)
@@ -760,9 +760,8 @@
             return;
         case 1:
-            Main.main.undoRedo.add(cmds.getFirst());
+            commitCommand(cmds.getFirst());
             break;
         default:
-            Command c = new SequenceCommand(tr(description), cmds);
-            Main.main.undoRedo.add(c);
+            commitCommand(new SequenceCommand(tr(description), cmds));
             break;
         }
@@ -770,4 +769,12 @@
         cmds.clear();
         cmdsCount++;
+    }
+
+    private static void commitCommand(Command c) {
+        if (Main.main != null) {
+            Main.main.undoRedo.add(c);
+        } else {
+            c.executeCommand();
+        }
     }
 
@@ -1279,5 +1286,5 @@
             if (!way.insideToTheRight) {
                 ReverseWayResult res = ReverseWayAction.reverseWay(way.way);
-                Main.main.undoRedo.add(res.getReverseCommand());
+                commitCommand(res.getReverseCommand());
                 cmdsCount++;
             }
@@ -1286,5 +1293,5 @@
         Pair<Way, Command> result = CombineWayAction.combineWaysWorker(actionWays);
 
-        Main.main.undoRedo.add(result.b);
+        commitCommand(result.b);
         cmdsCount++;
 
@@ -1536,13 +1543,15 @@
      */
     private void makeCommitsOneAction(String message) {
-        UndoRedoHandler ur = Main.main.undoRedo;
         cmds.clear();
-        int i = Math.max(ur.commands.size() - cmdsCount, 0);
-        for (; i < ur.commands.size(); i++) {
-            cmds.add(ur.commands.get(i));
-        }
-
-        for (i = 0; i < cmds.size(); i++) {
-            ur.undo();
+        if (Main.main != null) {
+            UndoRedoHandler ur = Main.main.undoRedo;
+            int i = Math.max(ur.commands.size() - cmdsCount, 0);
+            for (; i < ur.commands.size(); i++) {
+                cmds.add(ur.commands.get(i));
+            }
+
+            for (i = 0; i < cmds.size(); i++) {
+                ur.undo();
+            }
         }
 
Index: trunk/src/org/openstreetmap/josm/actions/PurgeAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/PurgeAction.java	(revision 11250)
+++ trunk/src/org/openstreetmap/josm/actions/PurgeAction.java	(revision 11252)
@@ -72,4 +72,5 @@
     protected transient OsmDataLayer layer;
     protected JCheckBox cbClearUndoRedo;
+    protected boolean modified;
 
     protected transient Set<OsmPrimitive> toPurge;
@@ -93,14 +94,32 @@
             return;
 
-        doPurge(getLayerManager().getEditDataSet().getAllSelected(), true);
-    }
-
-    /**
-     * Performs purge on selected OSM primitives.
+        PurgeCommand cmd = getPurgeCommand(getLayerManager().getEditDataSet().getAllSelected());
+        boolean clearUndoRedo = false;
+
+        if (!GraphicsEnvironment.isHeadless()) {
+            final boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
+                    "purge", Main.parent, buildPanel(modified), tr("Confirm Purging"),
+                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_OPTION);
+            if (!answer)
+                return;
+
+            clearUndoRedo = cbClearUndoRedo.isSelected();
+            Main.pref.put("purge.clear_undo_redo", clearUndoRedo);
+        }
+
+        Main.main.undoRedo.add(cmd);
+        if (clearUndoRedo) {
+            Main.main.undoRedo.clean();
+            getLayerManager().getEditDataSet().clearSelectionHistory();
+        }
+    }
+
+    /**
+     * Creates command to purge selected OSM primitives.
      * @param sel selected OSM primitives
-     * @param confirm asks user confirmation through a popup dialog
-     * @since 11240
-     */
-    public void doPurge(Collection<OsmPrimitive> sel, boolean confirm) {
+     * @return command to purge selected OSM primitives
+     * @since 11252
+     */
+    public PurgeCommand getPurgeCommand(Collection<OsmPrimitive> sel) {
         layer = Main.getLayerManager().getEditLayer();
 
@@ -204,5 +223,5 @@
         }
 
-        boolean modified = false;
+        modified = false;
         for (OsmPrimitive osm : toPurgeChecked) {
             if (osm.isModified()) {
@@ -212,24 +231,6 @@
         }
 
-        boolean clearUndoRedo = false;
-
-        if (!GraphicsEnvironment.isHeadless() && confirm) {
-            final boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
-                    "purge", Main.parent, buildPanel(modified), tr("Confirm Purging"),
-                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_OPTION);
-            if (!answer)
-                return;
-
-            clearUndoRedo = cbClearUndoRedo.isSelected();
-            Main.pref.put("purge.clear_undo_redo", clearUndoRedo);
-        }
-
-        Main.main.undoRedo.add(layer != null ? new PurgeCommand(layer, toPurgeChecked, makeIncomplete) :
-            new PurgeCommand(toPurgeChecked.iterator().next().getDataSet(), toPurgeChecked, makeIncomplete));
-
-        if (clearUndoRedo) {
-            Main.main.undoRedo.clean();
-            getLayerManager().getEditDataSet().clearSelectionHistory();
-        }
+        return layer != null ? new PurgeCommand(layer, toPurgeChecked, makeIncomplete) :
+            new PurgeCommand(toPurgeChecked.iterator().next().getDataSet(), toPurgeChecked, makeIncomplete);
     }
 
Index: trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java	(revision 11250)
+++ trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java	(revision 11252)
@@ -81,7 +81,4 @@
      */
     public static synchronized boolean isRightHandTraffic(LatLon ll) {
-        if (rlCache == null) {
-            initialize();
-        }
         return !rlCache.get(ll);
     }
@@ -137,5 +134,5 @@
         }
         // Purge all other ways and relations so dataset only contains lefthand traffic data
-        new PurgeAction().doPurge(toPurge, false);
+        new PurgeAction().getPurgeCommand(toPurge).executeCommand();
         // Combine adjacent countries into a single polygon
         Collection<Way> optimizedWays = new ArrayList<>();
