[fix] iprint should be a function parameter, not a global variable
[performance] reduce calculation time