Fixes to math library