Updated code to incorporate requestAnimationFrame. Should me a lot more efficient now.