Minimizing function debugged!