Switched from setTimeout to requestAnimationFrame