Revised MathLib and clean up