Adding a isLoop method an organizing the code