Fixed bugs in collision detection