Added collisionDetection() function