Using requestAnimationFrame for better performance