The looping function