loop logic cleanup