tidy code up, add some comments for future code, in partidular about collisions.