Handle cyclic dependencies

* The PR depends on #96.
* Please review only the second commit.