Changed: Improved implementation of the collision detection