The initial code
Added collisions
Improved collision algorithm

Rearranged the algorithm for increased speed