Added the 'hasCycle' method. And now returning from loops when the callback returns false.