Added min cost function