put cancelAnimationFrame in different place