changed loop to requestanimationframe