math refactor