created dynamic fitting function for fixing distortion