resolve #13 mainloop refactored to use request animation frame when possible