Index: /src/org/openstreetmap/josm/actions/DownloadIncompleteAction.java
===================================================================
--- /src/org/openstreetmap/josm/actions/DownloadIncompleteAction.java	(revision 174)
+++ /src/org/openstreetmap/josm/actions/DownloadIncompleteAction.java	(revision 175)
@@ -14,5 +14,7 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.visitor.MergeVisitor;
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
 import org.openstreetmap.josm.io.IncompleteDownloader;
@@ -46,4 +48,7 @@
 
 		@Override protected void finish() {
+			MergeVisitor merger = new MergeVisitor(Main.ds);
+			for (OsmPrimitive osm : reader.data.allPrimitives())
+				osm.visit(merger);
 			Main.parent.repaint();
 		}
Index: /src/org/openstreetmap/josm/actions/OpenAction.java
===================================================================
--- /src/org/openstreetmap/josm/actions/OpenAction.java	(revision 174)
+++ /src/org/openstreetmap/josm/actions/OpenAction.java	(revision 175)
@@ -69,5 +69,5 @@
 				DataSet dataSet;
 				if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) {
-					dataSet = OsmReader.parseDataSet(new FileInputStream(file), Main.ds, Main.pleaseWaitDlg);
+					dataSet = OsmReader.parseDataSet(new FileInputStream(file), null, Main.pleaseWaitDlg);
 				} else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) {
 					JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("CSV Data import for non-GPS data is not implemented yet."));
Index: /src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
===================================================================
--- /src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java	(revision 174)
+++ /src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java	(revision 175)
@@ -17,35 +17,39 @@
 import org.xml.sax.SAXException;
 
-public class DownloadGpsTask extends PleaseWaitRunnable implements DownloadTask {
-	private DownloadAction action;
-	private BoundingBoxDownloader reader;
-	private Collection<Collection<GpsPoint>> rawData;
+public class DownloadGpsTask implements DownloadTask {
+
+	private static class Task extends PleaseWaitRunnable {
+		private BoundingBoxDownloader reader;
+		private DownloadAction action;
+		private Collection<Collection<GpsPoint>> rawData;
+
+		public Task(BoundingBoxDownloader reader, DownloadAction action) {
+			super(tr("Downloading GPS data"));
+			this.reader = reader;
+			this.action = action;
+		}
+
+		@Override public void realRun() throws IOException, SAXException {
+			rawData = reader.parseRawGps();
+		}
+
+		@Override protected void finish() {
+			if (rawData == null)
+				return;
+			String name = action.latlon[0].getText() + " " + action.latlon[1].getText() + " x " + this.action.latlon[2].getText() + " " + this.action.latlon[3].getText();
+			Main.main.addLayer(new RawGpsLayer(rawData, name, null));
+		}
+
+		@Override protected void cancel() {
+			if (reader != null)
+				reader.cancel();
+		}
+	}
+
 	private JCheckBox checkBox = new JCheckBox(tr("Raw GPS data"));
 
-	public DownloadGpsTask() {
-		super(tr("Downloading GPS data"));
-	}
-
-	@Override public void realRun() throws IOException, SAXException {
-		rawData = reader.parseRawGps();
-	}
-
-	@Override protected void finish() {
-		if (rawData == null)
-			return;
-		String name = action.latlon[0].getText() + " " + action.latlon[1].getText() + " x " + this.action.latlon[2].getText() + " " + this.action.latlon[3].getText();
-		Main.main.addLayer(new RawGpsLayer(rawData, name, null));
-	}
-
-	@Override protected void cancel() {
-		if (reader != null)
-			reader.cancel();
-	}
-
-
 	public void download(DownloadAction action, double minlat, double minlon, double maxlat, double maxlon) {
-		this.action = action;
-		reader = new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon);
-		Main.worker.execute(this);
+		Task task = new Task(new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), action);
+		Main.worker.execute(task);
 	}
 
Index: /src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
===================================================================
--- /src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java	(revision 174)
+++ /src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java	(revision 175)
@@ -20,33 +20,37 @@
  * Run in the worker thread.
  */
-public class DownloadOsmTask extends PleaseWaitRunnable implements DownloadTask {
-	private BoundingBoxDownloader reader;
-	private DataSet dataSet;
+public class DownloadOsmTask implements DownloadTask {
+
+	private static class Task extends PleaseWaitRunnable {
+		private BoundingBoxDownloader reader;
+		private DataSet dataSet;
+
+		public Task(BoundingBoxDownloader reader) {
+			super(tr("Downloading data"));
+			this.reader = reader;
+		}
+
+		@Override public void realRun() throws IOException, SAXException {
+			dataSet = reader.parseOsm();
+		}
+
+		@Override protected void finish() {
+			if (dataSet == null)
+				return; // user cancelled download or error occoured
+			if (dataSet.allPrimitives().isEmpty())
+				errorMessage = tr("No data imported.");
+			Main.main.addLayer(new OsmDataLayer(dataSet, tr("Data Layer"), null));
+		}
+
+		@Override protected void cancel() {
+			if (reader != null)
+				reader.cancel();
+		}
+	}
 	private JCheckBox checkBox = new JCheckBox(tr("OpenStreetMap data"));
 
-	public DownloadOsmTask() {
-		super(tr("Downloading data"));
-	}
-
-	@Override public void realRun() throws IOException, SAXException {
-		dataSet = reader.parseOsm();
-	}
-
-	@Override protected void finish() {
-		if (dataSet == null)
-			return; // user cancelled download or error occoured
-		if (dataSet.allPrimitives().isEmpty())
-			errorMessage = tr("No data imported.");
-		Main.main.addLayer(new OsmDataLayer(dataSet, tr("Data Layer"), null));
-	}
-
-	@Override protected void cancel() {
-		if (reader != null)
-			reader.cancel();
-	}
-
 	public void download(DownloadAction action, double minlat, double minlon, double maxlat, double maxlon) {
-		reader = new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon);
-		Main.worker.execute(this);
+		Task task = new Task(new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon));
+		Main.worker.execute(task);
     }
 
Index: /src/org/openstreetmap/josm/data/osm/DataSet.java
===================================================================
--- /src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 174)
+++ /src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 175)
@@ -7,4 +7,5 @@
 import java.util.Iterator;
 import java.util.LinkedList;
+import java.util.List;
 
 import org.openstreetmap.josm.data.SelectionChangedListener;
@@ -12,10 +13,10 @@
 /**
  * DataSet is the data behind the application. It can consists of only a few
- * points up to the whole osm database. DataSet's can be merged together, 
+ * points up to the whole osm database. DataSet's can be merged together,
  * saved, (up/down/disk)loaded etc.
  *
- * Note, that DataSet is not an osm-primitive and so has no key association 
+ * Note, that DataSet is not an osm-primitive and so has no key association
  * but a few members to store some information.
- * 
+ *
  * @author imi
  */
@@ -35,8 +36,8 @@
 
 	/**
-	 * All ways (Streets etc.) in the DataSet. 
-	 * 
-	 * The nodes of the way segments of this way must be objects from 
-	 * the nodes list, however the way segments are stored only in the 
+	 * All ways (Streets etc.) in the DataSet.
+	 *
+	 * The nodes of the way segments of this way must be objects from
+	 * the nodes list, however the way segments are stored only in the
 	 * way list.
 	 */
@@ -49,9 +50,10 @@
 
 	/**
-	 * @return A collection containing all primitives (except keys) of the
-	 * dataset.
+	 * @return A collection containing all primitives of the dataset. The
+	 * data is ordered after: first comes nodes, then segments, then ways.
+	 * Ordering in between the categories is not guaranteed.
 	 */
-	public Collection<OsmPrimitive> allPrimitives() {
-		Collection<OsmPrimitive> o = new LinkedList<OsmPrimitive>();
+	public List<OsmPrimitive> allPrimitives() {
+		List<OsmPrimitive> o = new LinkedList<OsmPrimitive>();
 		o.addAll(nodes);
 		o.addAll(segments);
@@ -153,5 +155,5 @@
 
 	/**
-	 * Remove a listener from the selection changed listener list. 
+	 * Remove a listener from the selection changed listener list.
 	 * If <code>null</code> is passed, nothing happens.
 	 * @param listener The listener to remove from the list.
Index: /src/org/openstreetmap/josm/gui/MainMenu.java
===================================================================
--- /src/org/openstreetmap/josm/gui/MainMenu.java	(revision 174)
+++ /src/org/openstreetmap/josm/gui/MainMenu.java	(revision 175)
@@ -29,7 +29,7 @@
  * This is the JOSM main menu bar. It is overwritten to initialize itself and provide
  * all menu entries as member variables (sort of collect them).
- * 
+ *
  * It also provides possibilities to attach new menu entries (used by plugins).
- * 
+ *
  * @author Immanuel.Scholz
  */
@@ -52,5 +52,5 @@
 	public final HelpAction help = new HelpAction();
 	public final Action about = new AboutAction();
-	
+
 	public final JMenu layerMenu = new JMenu(tr("Layer"));
 	public final JMenu editMenu = new JMenu(tr("Edit"));
@@ -61,5 +61,5 @@
 
 
-	
+
 	public MainMenu() {
 		fileMenu.setMnemonic('F');
Index: /src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java
===================================================================
--- /src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java	(revision 174)
+++ /src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java	(revision 175)
@@ -66,9 +66,16 @@
 			// show the dialog
 			closeDialogCalled = false;
-			EventQueue.invokeLater(new Runnable() {
-				public void run() {
-					Main.pleaseWaitDlg.setVisible(true);
-				}
-			});
+			synchronized (this) {
+	            EventQueue.invokeLater(new Runnable() {
+	            	public void run() {
+	            		synchronized (PleaseWaitRunnable.this) {
+	            			PleaseWaitRunnable.this.notifyAll();
+	            		}
+	            		Main.pleaseWaitDlg.setVisible(true);
+	            	}
+	            });
+	            try {wait();} catch (InterruptedException e) {}
+			}
+
 
 			realRun();
@@ -119,4 +126,5 @@
 					} finally {
 						Main.pleaseWaitDlg.setVisible(false);
+						Main.pleaseWaitDlg.dispose();
 					}
 					if (errorMessage != null)
Index: /src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java
===================================================================
--- /src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java	(revision 174)
+++ /src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java	(revision 175)
@@ -105,5 +105,5 @@
 		settings.add(new PluginPreference());
 		settings.add(Main.toolbar);
-		
+
 		for (PluginProxy plugin : Main.plugins) {
 			PreferenceSetting p = plugin.getPreferenceSetting();
Index: /src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
===================================================================
--- /src/org/openstreetmap/josm/io/BoundingBoxDownloader.java	(revision 174)
+++ /src/org/openstreetmap/josm/io/BoundingBoxDownloader.java	(revision 175)
@@ -37,4 +37,5 @@
      */
     public Collection<Collection<GpsPoint>> parseRawGps() throws IOException, SAXException {
+		Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));
     	try {
     		String url = "trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page=";
@@ -84,9 +85,10 @@
     public DataSet parseOsm() throws SAXException, IOException {
     	try {
+    		Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));
     		final InputStream in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2, Main.pleaseWaitDlg);
     		if (in == null)
     			return null;
     		Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));
-    		final DataSet data = OsmReader.parseDataSet(in, Main.ds, Main.pleaseWaitDlg);
+    		final DataSet data = OsmReader.parseDataSet(in, null, Main.pleaseWaitDlg);
     		in.close();
     		activeConnection = null;
Index: /src/org/openstreetmap/josm/io/IncompleteDownloader.java
===================================================================
--- /src/org/openstreetmap/josm/io/IncompleteDownloader.java	(revision 174)
+++ /src/org/openstreetmap/josm/io/IncompleteDownloader.java	(revision 175)
@@ -12,4 +12,5 @@
 
 import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.Segment;
@@ -23,5 +24,5 @@
 /**
  * Capable of downloading ways without having to fully parse their segments.
- * 
+ *
  * @author Imi
  */
@@ -29,9 +30,14 @@
 
 	/**
+	 * The new downloaded data will be inserted here.
+	 */
+	public final DataSet data = new DataSet();
+
+	/**
 	 * The list of incomplete Ways to download. The ways will be filled and are complete after download.
 	 */
 	private final Collection<Way> toDownload;
-	private MergeVisitor merger = new MergeVisitor(Main.ds);
-	
+	private MergeVisitor merger = new MergeVisitor(data);
+
 	public IncompleteDownloader(Collection<Way> toDownload) {
 		this.toDownload = toDownload;
@@ -85,8 +91,6 @@
 			SegmentParser segmentParser = new SegmentParser();
 			segmentParser.parse(new StringReader(segBuilder.toString()));
-			if (segmentParser.from == 0 || segmentParser.to == 0) {
-				System.out.println(segBuilder.toString());
+			if (segmentParser.from == 0 || segmentParser.to == 0)
 				throw new SAXException("Invalid segment response.");
-			}
 			if (!hasNode(segmentParser.from))
 				readNode(segmentParser.from, s.id).visit(merger);
@@ -105,10 +109,10 @@
 
 	private Segment readSegment(String seg) throws SAXException, IOException {
-        return OsmReader.parseDataSet(new ByteArrayInputStream(seg.getBytes("UTF-8")), Main.ds, null).segments.iterator().next();
+        return OsmReader.parseDataSet(new ByteArrayInputStream(seg.getBytes("UTF-8")), data, null).segments.iterator().next();
     }
 
 	private Node readNode(long id, long segId) throws SAXException, IOException {
 		try {
-	        return OsmReader.parseDataSet(getInputStream("node/"+id, null), Main.ds, null).nodes.iterator().next();
+	        return OsmReader.parseDataSet(getInputStream("node/"+id, null), data, null).nodes.iterator().next();
         } catch (FileNotFoundException e) {
 	        e.printStackTrace();
Index: /src/org/openstreetmap/josm/io/OsmReader.java
===================================================================
--- /src/org/openstreetmap/josm/io/OsmReader.java	(revision 174)
+++ /src/org/openstreetmap/josm/io/OsmReader.java	(revision 175)
@@ -192,4 +192,7 @@
 	    	if (node.id == id)
 	    		return node;
+	    for (Node node : Main.ds.nodes)
+	    	if (node.id == id)
+	    		return node;
 	    return null;
     }
@@ -200,4 +203,7 @@
 			return s;
 		for (Segment seg : references.segments)
+			if (seg.id == id)
+				return seg;
+		for (Segment seg : Main.ds.segments)
 			if (seg.id == id)
 				return seg;
@@ -228,9 +234,10 @@
 	/**
 	 * Parse the given input source and return the dataset.
-	 * @param pleaseWaitDlg TODO
+	 * @param ref The dataset that is search in for references first. If
+	 * 	the Reference is not found here, Main.ds is searched.
 	 */
 	public static DataSet parseDataSet(InputStream source, DataSet ref, PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException {
 		OsmReader osm = new OsmReader();
-		osm.references = ref;
+		osm.references = ref == null ? new DataSet() : ref;
 
 		// phase 1: Parse nodes and read in raw segments and ways
Index: /src/org/openstreetmap/josm/io/OsmServerReader.java
===================================================================
--- /src/org/openstreetmap/josm/io/OsmServerReader.java	(revision 174)
+++ /src/org/openstreetmap/josm/io/OsmServerReader.java	(revision 175)
@@ -27,4 +27,8 @@
 		URL url = new URL(urlStr);
 		activeConnection = (HttpURLConnection)url.openConnection();
+		if (cancel) {
+			activeConnection.disconnect();
+			return null;
+		}
 		System.out.println("got return: "+activeConnection.getResponseCode());
 		activeConnection.setConnectTimeout(15000);
