Corrected bug on the collision detection