Fixed an error in collision detection