now using requestanimationframe instead of setTimeout