Using requestAnimationFrame instead of setTimeout