Moved animation to a function