Index: /applications/editors/josm/plugins/pdfimport/src/pdfimport/PathOptimizer.java
===================================================================
--- /applications/editors/josm/plugins/pdfimport/src/pdfimport/PathOptimizer.java	(revision 24068)
+++ /applications/editors/josm/plugins/pdfimport/src/pdfimport/PathOptimizer.java	(revision 24069)
@@ -354,5 +354,5 @@
 						//remove excess segments from start of chain
 						while (lastPoint != firstPoint) {
-							PdfPath pathToRemove = pathChain.get(0);
+							PdfPath pathToRemove = pathChain.remove(0);							
 							firstPoint = pathToRemove.getOtherEnd(firstPoint);
 						}
@@ -379,5 +379,5 @@
 					pathChain.add(0, firstPath);
 
-					if (!pointsInPath.contains(nextPoint)) {
+					if (!pointsInPath.contains(firstPoint)) {
 						pointsInPath.add(firstPoint);
 						changed = true;
@@ -388,5 +388,5 @@
 						//remove excess segments from end of chain
 						while (lastPoint != firstPoint) {
-							PdfPath pathToRemove = pathChain.get(pathChain.size() - 1);
+							PdfPath pathToRemove = pathChain.remove(pathChain.size() - 1);
 							lastPoint = pathToRemove.getOtherEnd(lastPoint);
 						}
