Changed to use requestAnimationFrame