beefed up prim math functions