changed to use requestAnimationFrame