Fixed bugs in the physics engine