handling self-collisions