Created a method that cheks for loops
Changed var to method for checking loops