Fixed dependency tree builder to avoid cyclic infinite loop.