Added detecting cycles and longest line