Improve circular dependencies resolution.

TODO: More complex setups cause infinite recursion.
Merge pull request #26 from drodriguez/fix-circular-dependencies

Improve circular dependencies resolution.