diff --git a/src/main/java/info/textgrid/services/aggregator/tree/Aggregation.java b/src/main/java/info/textgrid/services/aggregator/tree/Aggregation.java
index 153f0725deb7d95b179bbfb1dbb0a23a12d3e769..5458c084a3df1aeaa56308316279d51f02eb8985 100644
--- a/src/main/java/info/textgrid/services/aggregator/tree/Aggregation.java
+++ b/src/main/java/info/textgrid/services/aggregator/tree/Aggregation.java
@@ -5,6 +5,7 @@
 import java.util.List;
 
 import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 
 public class Aggregation extends AggregationEntry {
@@ -21,12 +22,16 @@ public Aggregation(final ObjectType metadata, final Aggregation parent) {
 
 	@Override
 	public String toString() {
-		return super.toString() + ": [" + Joiner.on(", ").join(children) + "]";
+		return super.toString() + ": [" + (children == null? "!!!" : Joiner.on(", ").join(children)) + "]";
 	}
 
 	protected Aggregation add(final AggregationEntry child) {
 		children.add(child);
 		return this;
 	}
+	
+	public List<AggregationEntry> getChildren() {
+		return ImmutableList.copyOf(children);
+	}
 
 }
diff --git a/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java b/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java
index 881cdc7be623b123925d4381ae961b6de414cd11..d545aa195959abe970e69e7f20560b0c11c80575 100644
--- a/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java
+++ b/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java
@@ -5,6 +5,7 @@
 import java.io.File;
 import java.net.URI;
 import java.text.MessageFormat;
+import java.util.logging.Logger;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
@@ -13,29 +14,31 @@
  * Represents an entry in an aggregation.
  */
 public class AggregationEntry {
+	
+	private static Logger logger = Logger.getLogger("info.textgrid.services.aggregator.tree");
 
 	private final ObjectType metadata;
 
-	protected final ImmutableList<Aggregation> path;
+	protected final Optional<Aggregation> parent;
 
 	protected AggregationEntry(final ObjectType metadata) {
-		this.metadata = metadata;
-		path = ImmutableList.of();
+		this(metadata, null);
 	}
 
 	protected AggregationEntry(final ObjectType metadata,
 			final Aggregation parent) {
-		path = ImmutableList.<Aggregation> builder().addAll(parent.path)
-				.add(parent).build();
 		this.metadata = metadata;
-		parent.add(this);
+		this.parent = Optional.fromNullable(parent);
+		if (this.parent.isPresent()) {
+			parent.add(this);
+			logger.info(MessageFormat.format("{0} has parent {1}", this, parent));
+		} else {
+			logger.info(MessageFormat.format("{0} has no parent", this));
+		}
 	}
 
 	protected Optional<Aggregation> getParent() {
-		if (path.isEmpty())
-			return Optional.absent();
-		else
-			return Optional.of(path.get(path.size() - 1));
+		return parent;
 	}
 
 	public ObjectType getMetadata() {
@@ -53,10 +56,10 @@ protected String getSimpleFileName(final boolean withExtension) {
 				getMetadata().getGeneric().getGenerated().getTextgridUri()
 						.getValue()).getSchemeSpecificPart();
 		if (withExtension)
-			return baseName;
-		else
 			return FileExtensionMap.getInstance().addExtension(baseName,
 					getMetadata().getGeneric().getProvided().getFormat());
+		else
+			return baseName;
 	}
 
 	/**
@@ -73,7 +76,7 @@ protected File getFileName(final boolean withExtension) {
 			return new File(parent.get().getFileName(false),
 					getSimpleFileName(withExtension));
 		else
-			return new File(getSimpleFileName(false));
+			return new File(getSimpleFileName(withExtension));
 	}
 
 	/**
diff --git a/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java b/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java
index 0a43829b044eaf0cbe83ac4b3e942cfb2395946d..3db55f0b88aca8f6e59644a84141f77898ea198b 100644
--- a/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java
+++ b/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java
@@ -2,20 +2,26 @@
 
 import info.textgrid.namespaces.metadata.core._2010.ObjectType;
 import info.textgrid.services.aggregator.AggregationTreeWalker;
+import info.textgrid.services.aggregator.ITextGridRep;
 
+import java.text.MessageFormat;
 import java.util.Deque;
+import java.util.logging.Logger;
 
 import com.google.common.collect.Lists;
 
 public class AggregationTreeFactory extends AggregationTreeWalker {
 
 	private final Deque<Aggregation> stack = Lists.newLinkedList();
-	private final Aggregation root;
+	private Aggregation root;
+	private static Logger logger = Logger.getLogger("info.textgrid.services.aggregator.tree");
 
-	protected AggregationTreeFactory(final ObjectType root) {
+	protected AggregationTreeFactory(final ObjectType root, ITextGridRep repository, String sid) {
 		super();
-		this.root = new Aggregation(root);
-		stack.push(this.root);
+		this.setRepository(repository);
+		this.setSid(sid);
+//		this.root = new Aggregation(root);
+//		stack.push(this.root);
 		walkAggregation(root, false);
 	}
 
@@ -34,15 +40,16 @@ protected void walkAggregation(final ObjectType aggregation,
 			final boolean again) {
 		stack.push(new Aggregation(aggregation, stack.peek()));
 		super.walkAggregation(aggregation, again);
-		stack.pop();
+		logger.info(MessageFormat.format("Walking aggregation {0}", stack.peek()));
+		this.root = stack.pop();
 	}
 
 	protected Aggregation getRoot() {
 		return root;
 	}
 
-	public static Aggregation create(final ObjectType root) {
-		return new AggregationTreeFactory(root).getRoot();
+	public static Aggregation create(final ObjectType root, ITextGridRep repository, String sid) {
+		return new AggregationTreeFactory(root, repository, sid).getRoot();
 	}
 
 }