loop function finalization