Index: applications/editors/josm/plugins/terracer/src/terracer/ReverseTerraceAction.java
===================================================================
--- applications/editors/josm/plugins/terracer/src/terracer/ReverseTerraceAction.java	(revision 19658)
+++ applications/editors/josm/plugins/terracer/src/terracer/ReverseTerraceAction.java	(revision 19678)
@@ -6,6 +6,9 @@
 import java.awt.event.KeyEvent;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.LinkedList;
+
+import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
@@ -49,28 +52,41 @@
      */
     public void actionPerformed(ActionEvent e) {
-        Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
+        Collection<Way> selectedWays = Main.main.getCurrentDataSet().getSelectedWays();
 
-        // set to keep track of all the nodes that have been visited - that is: if
+        // Set to keep track of all the nodes that have been visited - that is: if
         // we encounter them again we will not follow onto the connected ways.
         HashSet<Node> visitedNodes = new HashSet<Node>();
 
-        // set to keep track of the ways the algorithm has seen, but not yet visited.
-        // since when a way is visited all of its nodes are marked as visited, there
+        // Set to keep track of the ways the algorithm has seen, but not yet visited.
+        // Since when a way is visited all of its nodes are marked as visited, there
         // is no need to keep a visitedWays set.
         HashSet<Way> front = new HashSet<Way>();
 
-        // initialise the set with all the buildings in the selection. this means
-        // there is undefined behaviour when there is a multiple selection, as the
-        // ordering will be based on the hash.
-        for (OsmPrimitive prim : sel) {
-            if (prim.keySet().contains("building") && prim instanceof Way) {
-                front.add((Way)prim);
+        // Find the first or last way from the teracced houses.
+        // It should be connected to exactly one other way.
+        for (Way w : selectedWays) {
+            int conn = 0;
+            for (Way v : selectedWays) {
+                if (w.equals(v)) continue;
+                if (!Collections.disjoint(w.getNodes(), v.getNodes())) {
+                    ++conn;
+                }
+            }
+            if (conn == 1) {
+                front.add(w);
+                break;
             }
         }
+        
+        if (front.isEmpty()) {
+            JOptionPane.showMessageDialog(Main.parent,
+                    tr("Cannot reverse!"));
+            return;
+        }                
 
-        // this is like a visitedWays set, but in a linear order.
+        // This is like a visitedWays set, but in a linear order.
         LinkedList<Way> orderedWays = new LinkedList<Way>();
 
-        // and the tags to reverse on the orderedWays.
+        // And the tags to reverse on the orderedWays.
         LinkedList<String> houseNumbers = new LinkedList<String>();
 
@@ -79,5 +95,5 @@
             Way w = front.iterator().next();
 
-            // visit all the nodes in the way, adding the building's they're members of
+            // Visit all the nodes in the way, adding the building's they're members of
             // to the front.
             for (Node n : w.getNodes()) {
@@ -92,5 +108,5 @@
             }
 
-            // we've finished visiting this way, so record the attributes we're interested
+            // We've finished visiting this way, so record the attributes we're interested
             // in for re-writing.
             front.remove(w);
@@ -100,5 +116,4 @@
 
         Collection<Command> commands = new LinkedList<Command>();
-        // what, no zipWith?
         for (int i = 0; i < orderedWays.size(); ++i) {
             commands.add(new ChangePropertyCommand(
@@ -112,3 +127,7 @@
     }
 
+    @Override
+    protected void updateEnabledState() {
+        setEnabled(getCurrentDataSet() != null);
+    }    
 }
Index: applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
===================================================================
--- applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java	(revision 19658)
+++ applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java	(revision 19678)
@@ -34,4 +34,5 @@
 import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.data.osm.RelationMember;
+import org.openstreetmap.josm.data.osm.TagCollection;
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.tools.Pair;
@@ -209,4 +210,8 @@
             terr.addNode(new_nodes[1][i]);
             terr.addNode(new_nodes[0][i]);
+            
+            // add the tags of the outline to each building (e.g. source=*)
+            TagCollection.from(outline).applyTo(terr);
+            
             if (from != null) {
                 // only, if the user has specified house numbers
@@ -459,3 +464,8 @@
         return n;
     }
+
+    @Override
+    protected void updateEnabledState() {
+        setEnabled(getCurrentDataSet() != null);
+    }    
 }
