MathLibs refactoring