updated distortion algorithm