Handle cyclic dependencies

* The PR depends on #96.
* Please review only the second commit.
It would be nice to have an error as in A -> B -> C -> B hence error.