reworked the math functions