some more math corrections (partially tested)