improving mathematical functions in cause of a bug