--- a/bundle.py
+++ b/bundle.py
@@ -8,19 +8,21 @@
 from zeroinstall.injector.iface_cache import iface_cache
 import __main__
 
-def iface_to_dir_name(iface):
+def iface_to_dir_name(iface_uri):
 	"""Pick a directory name for this interface's implementation."""
-	return iface.get_name().replace(' ', '_').replace('/', '-')
+	feed = iface_cache.get_feed(iface_uri)
+	assert feed
+	return feed.get_name().replace(' ', '_').replace('/', '-')
 
 class BundleMaker(saving.Saveable):
-	def __init__(self, policy):
-		assert policy.ready
+	def __init__(self, sels):
+		assert sels
 
-		self.policy = policy
-		iface = self.policy.get_interface(policy.root)
+		self.sels = sels
+		iface = iface_cache.get_interface(sels.interface)
 		self.icon = iface_cache.get_icon_path(iface)
 
-		self.impl = self.policy.implementation[iface]
+		self.impl = sels.selections[sels.interface]
 		if hasattr(self.impl, 'main'):
 			self.main = self.impl.main
 		else:
@@ -32,7 +34,8 @@
 
 	def save_to_file(self, path):
 		os.mkdir(path)
-		assert "'" not in self.policy.root
+		iface_uri = self.sels.interface
+		assert "'" not in iface_uri
 
 		apprun = os.fdopen(os.open(os.path.join(path, 'AppRun'), os.O_CREAT | os.O_WRONLY, 0777), 'w')
 		apprun.write("""#!/bin/sh
@@ -40,25 +43,23 @@
 APP_DIR=`dirname "$0"`
 """)
 
-		iface = self.policy.get_interface(self.policy.root)
-			
 		# Copy each implementation into the bundle and set any
 		# environment variables required to find it
 		bindings = []
-		for needed_iface in self.policy.implementation:
-			impl = self.policy.implementation[needed_iface]
+		for needed_iface, impl in self.sels.selections.iteritems():
 			impl_copy = os.path.join(path, iface_to_dir_name(needed_iface))
 			assert impl
-			shutil.copytree(self.policy.get_implementation_path(impl), impl_copy)
+			assert impl.digests, "No digest for %s" % (impl)	# TODO: --no-local?
+			shutil.copytree(iface_cache.stores.lookup_any(impl.digests), impl_copy)
 
-			for dep in impl.dependencies.values():
+			for dep in impl.dependencies:
 				for b in dep.bindings:
 					bindings.append((dep, b))
 
 		for (dep, binding) in bindings:
-			dep_iface = self.policy.get_interface(dep.interface)
 			if isinstance(b, EnvironmentBinding):
-				dep_name = os.path.join(iface_to_dir_name(dep_iface), b.insert)
+				dep_name = os.path.join(iface_to_dir_name(dep.interface), b.insert)
+				# XXX: mode?
 				apprun.write("""
 if [ "x$%s" = x ]; then
   %s="$APP_DIR/%s"
@@ -67,14 +68,12 @@
 fi
 export %s
 """ % (b.name, b.name, dep_name, b.name, dep_name, b.name, b.name))
-				dep_impl = self.policy.get_implementation(dep_iface)
 			else:
 				print >>sys.stderr, "Warning: unknown binding type " + b
 		
-		root_iface = self.policy.get_interface(self.policy.root)
-		root_impl = self.policy.get_implementation(root_iface)
+		root_impl = self.sels.selections[self.sels.interface]
 
-		impl_apprun = os.path.join(iface_to_dir_name(root_iface), root_impl.main)
+		impl_apprun = os.path.join(iface_to_dir_name(self.sels.interface), root_impl.main)
 		apprun.write('exec "$APP_DIR/%s" "$@"\n' % impl_apprun)
 
 		apprun.close()
@@ -82,7 +81,10 @@
 		if self.icon:
 			shutil.copyfile(self.icon, os.path.join(path, '.DirIcon'))
 
-		if self.is_applet(root_iface):
+		impl_path = iface_cache.stores.lookup_any(root_impl.digests)
+		assert impl_path
+		applet_run = os.path.join(impl_path, os.path.dirname(root_impl.main), 'AppletRun')
+		if os.path.exists(applet_run):
 			os.symlink('AppRun', os.path.join(path, 'AppletRun'))
 
 		appinfo = os.path.join(os.path.dirname(impl_apprun), 'AppInfo.xml')
@@ -116,10 +118,3 @@
 		item = parent.ownerDocument.createElement(name)
 		parent.appendChild(item)
 		return item
-
-	def is_applet(self, iface):
-		impl_path = self.policy.get_implementation_path(self.impl)
-		assert impl_path
-
-		applet_run = os.path.join(impl_path, os.path.dirname(self.main), 'AppletRun')
-		return os.path.exists(applet_run)