002: added calculation of h, improved performance, better readability