moved the loop animation to a separate function