Adding requestAnimationFrame polyfill, cleaned up code.