cycle detection and graph clear methods added