Simple dependency algorithm

From this blog
http://www.electricmonk.nl/log/2008/08/07/dependency-resolving-algorithm/