replaced setInterval with window.requestAnimationFrame