Working version.
Corrected errors on collisions.