Optimization of Mechanisms by using a Minimum Distance Function