fixed several math errors and tweaked physics engine