Index: applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java
===================================================================
--- applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java	(revision 25199)
+++ applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java	(revision 26029)
@@ -22,13 +22,12 @@
 
 import javax.swing.JButton;
+import javax.swing.JOptionPane;
 import javax.swing.JTextField;
-import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.data.osm.Node;
-import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.Relation;
 import org.openstreetmap.josm.actions.JosmAction;
 import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
 
@@ -44,10 +43,10 @@
  */
 public class HouseNumberInputHandler extends JosmAction implements ActionListener, FocusListener, ItemListener {
-    private TerracerAction terracerAction;
-    private Way outline, street;
-    private String streetName;
-    private Node init;
-    private Relation associatedStreet;
-    private ArrayList<Node> housenumbers;
+    private final TerracerAction terracerAction;
+    private final Way outline, street;
+    private final String streetName;
+    private final Node init;
+    private final Relation associatedStreet;
+    private final ArrayList<Node> housenumbers;
     public HouseNumberInputDialog dialog;
 
@@ -127,5 +126,5 @@
         // Allow non numeric characters for the low number as long as there is
         // no high number of the segmentcount is 1
-        if (dialog.hi.getText().length() > 0 | segments() > 1) {
+        if (dialog.hi.getText().length() > 0 && (segments()!= null || segments() < 1)) {
             isOk = isOk
                     && checkNumberStringField(dialog.lo, tr("Lowest number"),
@@ -281,8 +280,9 @@
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
      * Called when the user selects from a pulldown selection
      */
+    @Override
     public void itemStateChanged(ItemEvent e) {
         validateInput();
@@ -291,7 +291,8 @@
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
      */
+    @Override
     public void actionPerformed(final ActionEvent e) {
         // OK or Cancel button-actions
@@ -391,5 +392,5 @@
         } else {
             String name;
-            if (selected instanceof AutoCompletionListItem) 
+            if (selected instanceof AutoCompletionListItem)
             {
                name = ((AutoCompletionListItem)selected).getValue();
@@ -436,4 +437,5 @@
      * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
      */
+    @Override
     public void focusGained(FocusEvent e) {
         // Empty, but placeholder is required
@@ -445,4 +447,5 @@
      * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
      */
+    @Override
     public void focusLost(FocusEvent e) {
         if (e.getOppositeComponent() == null)
Index: applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
===================================================================
--- applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java	(revision 25199)
+++ applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java	(revision 26029)
@@ -20,7 +20,6 @@
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
-import java.util.Map.Entry;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -31,10 +30,9 @@
 import org.openstreetmap.josm.actions.JosmAction;
 import org.openstreetmap.josm.command.AddCommand;
+import org.openstreetmap.josm.command.ChangeCommand;
 import org.openstreetmap.josm.command.ChangePropertyCommand;
-import org.openstreetmap.josm.command.ChangeCommand;
 import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.command.DeleteCommand;
 import org.openstreetmap.josm.command.SequenceCommand;
-import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -80,4 +78,5 @@
      * calls to terraceBuilding(), which does all the real work.
      */
+    @Override
     public void actionPerformed(ActionEvent e) {
         Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
@@ -229,5 +228,5 @@
     /**
      * Sorts the house number nodes according their numbers only
-     * 
+     *
      * @param house
      *            number nodes
@@ -238,5 +237,5 @@
         /*
          * (non-Javadoc)
-         * 
+         *
          * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
          */
@@ -343,5 +342,9 @@
 
         // new nodes array to hold all intermediate nodes
+        // This set will contain at least 4 existing nodes from the original outline (those, which coordinates match coordinates of outline nodes)
         Node[][] new_nodes = new Node[2][nb + 1];
+        // This list will contain nodes of the outline that are used in new lines.
+        // These nodes will not be deleted with the outline (if deleting was prompted).
+        ArrayList<Node> reused_nodes = new ArrayList<Node>();
 
         this.commands = new LinkedList<Command>();
@@ -353,6 +356,12 @@
                 new_nodes[0][i] = interpolateAlong(interp.a, frontLength * i_dir / nb);
                 new_nodes[1][i] = interpolateAlong(interp.b, backLength * i_dir / nb);
-                this.commands.add(new AddCommand(new_nodes[0][i]));
-                this.commands.add(new AddCommand(new_nodes[1][i]));
+                if (!outline.containsNode(new_nodes[0][i]))
+                    this.commands.add(new AddCommand(new_nodes[0][i]));
+                else
+                    reused_nodes.add(new_nodes[0][i]);
+                if (!outline.containsNode(new_nodes[1][i]))
+                    this.commands.add(new AddCommand(new_nodes[1][i]));
+                else
+                    reused_nodes.add(new_nodes[1][i]);
             }
 
@@ -389,5 +398,15 @@
 
             if (deleteOutline) {
-                this.commands.add(DeleteCommand.delete(Main.main.getEditLayer(), Collections.singleton(outline), true, true));
+                // Delete outline nodes having no tags and referrers but the outline itself
+                List<Node> nodes = outline.getNodes();
+                ArrayList<Node> nodesToDelete = new ArrayList<Node>();
+                for (Node n : nodes)
+                    if (!n.hasKeys() && n.getReferrers().size() == 1 && !reused_nodes.contains(n))
+                        nodesToDelete.add(n);
+                if (nodesToDelete.size() > 0)
+                    this.commands.add(DeleteCommand.delete(Main.main.getEditLayer(), nodesToDelete));
+                // Delete the way itself without nodes
+                this.commands.add(DeleteCommand.delete(Main.main.getEditLayer(), Collections.singleton(outline), false, true));
+
             }
         } else {
@@ -532,6 +551,5 @@
         // if side2 is contiguous with side1 then look further down the
         // list. we know there are at least 4 sides, as anything smaller
-        // than a quadrilateral would have been rejected at an earlier
-        // stage.
+        // than a quadrilateral would have been rejected at an earlier stage.
         if (indexDistance(side1, side2, indexes.length) < 2) {
             side2 = indexes[2];
@@ -547,6 +565,6 @@
         // same for all sides.
         if (sideLength(w, side1) > sideLength(w, side1 + 1)
-                && Math.abs(sideness[side1] - sideness[side1 + 1]) < 0.001) {
-            side1 = side1 + 1;
+                && Math.abs(sideness[side1] - sideness[(side1 + 1) % (w.getNodesCount() - 1)]) < 0.001) {
+            side1 = (side1 + 1) % (w.getNodesCount() - 1);
             side2 = (side2 + 1) % (w.getNodesCount() - 1);
         }
@@ -628,4 +646,5 @@
             }
 
+            @Override
             public int compareTo(SortWithIndex o) {
                 return Double.compare(x, o.x);
@@ -686,11 +705,17 @@
      * nodes. Interpolates linearly in projected coordinates.
      *
+     * If new node coordinate matches a or b coordinates, a or b is returned.
+     *
      * @param a First node, at which f=0.
      * @param b Last node, at which f=1.
      * @param f Fractional position between first and last nodes.
-     * @return A new node at the interpolated position.
+     * @return A new node at the interpolated position (or a or b in case if f ≈ 0 or f ≈ 1).
      */
     private Node interpolateNode(Node a, Node b, double f) {
         Node n = new Node(a.getEastNorth().interpolate(b.getEastNorth(), f));
+        if (n.getCoor().equalsEpsilon(a.getCoor()))
+            return a;
+        if (n.getCoor().equalsEpsilon(b.getCoor()))
+            return b;
         return n;
     }
