better code vor robust fitting