Change loop logic