Updated collision detection code to use requestAnimationFrame. Pulled out common code to single files.