Cleaned the minimize() function