refactor animation function recursively