changed to use window.animationFrame rather than timer