Implemented better collision detection.