general math refactor