added one more function, mathematical algorithm optimized