added ability to stop optimization when cost gets below min_cost