Fixed bug in collision detection