added latest collision detection code.