Improve dependency handling code

These modifications make it much easier to handle, to understand an to
explain.
Determining installed state by class-type is still a bit wacky, that's
something to change in future.