finally fixed the collision detection