in the process of generalizing to next, but stuck on explanation graph cycle detection