refactoring math module (not done yet)