optimization function Gauss - not tested