Add detection of infinite loops and self-loops.
Add nice exception handling.
Merge remote-tracking branch 'upstream/master'