setTimeout replaced with requestAnimationFrame.