Optimizing distortion correction