switched animate function to use requestAnimationFrame