Fixed requestAnimFrame being called in the wrong place