Simplified the new code for collision detection.