Dev/detect cycles

- use tarjan algorithm for detecting cycles in graphs
- fix #21