refactoring math utils