Minor fixes to how dependencies are resolved.

Instead of always preferring the stricter definition on all instances,
this commit adds a more complicated way of choosing.