Simplify and refactor most math functions to map_math()