Implements requestAnimationFrame for better timing