Added self-collision check