Fixed numerous bugs in dependency calculation and collection cloning.