Refactored animateSVG script