Refactored math functions into reusables functions