Optimization of Petrick's method.