separate math function
improve readability of code