Improved some script, demo, and cycle detection code.
Fixed tree equality code, cycle detection.