changed cost function