updated math function now working