modified the collision detection to work more efficiently