Prevent infinte cycle when printing nodes
Add cycle detection